我想使用ggplot2突出显示密度的边界线,颜色与我用于填充的颜色相同,只是略深一些.这是一个小例子:
ggplot(chickwts, aes(x = weight)) +
geom_density(bins = 25, aes(fill = feed, colour = feed)) +
facet_wrap(~feed) +
ylab(NULL) +
theme_minimal() +
theme(text = element_text(family = "Georgia", size = 12, face = "bold"),
legend.position = "none")
Run Code Online (Sandbox Code Playgroud)
这给了我以下情节:
我理想的是用这些相同颜色显示密度的边界线,但略深一些.我可以手动执行此操作scale_colour_ manual(),但我真的不想这样做.有没有办法用ggplot2做这个,也许有alpha()或类似的东西?
小智 7
默认的离散比例是hcl这样你可以将其l值变暗:
last_plot() + scale_colour_hue(l = 40)
Run Code Online (Sandbox Code Playgroud)
您只需要添加alpha参数:
geom_density(bins = 25, aes(fill = feed, colour = feed), alpha=0.3)
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助