【发布时间】:2014-10-07 07:28:08
【问题描述】:
我正在尝试在 ggplot2 中绘制一些重叠的密度图。我遇到了一个问题,我无法从图例中删除斜线。我尝试过使用 scale_fill_manual() 和 legend.key 以及来自 R Cookbook 的 hack,但我似乎无法正确使用。
data(iris)
iris=iris
cols=brewer.pal(3,"Set1")
ggplot(iris) +
geom_density(position="identity",aes(x=iris$Sepal.Length,fill=cols[1]),
colour="black",alpha=.5) +
geom_density(position="identity",aes(x=iris$Sepal.Width,fill=cols[2]),
colour="black",alpha=.5)+
theme_bw() +
scale_fill_identity(guide="legend",labels=c("Sepal Width","Sepal Length"))+
xlab("X axis") +
theme(panel.background=element_blank(),
legend.title=element_blank(),
legend.key = element_rect(),
legend.background = element_blank(),
legend.justification=c(1,0),
legend.position=c(.75,.5),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank())
我能做些什么来解决这个问题?
【问题讨论】: