我有下面的plto
我该怎么做:
(1)删除sizze图例。
(2)将条形图的颜色设为蓝色,图例说明"条纹图例"。另外,如何删除条形图例方块中的黑点。
(3)将点的颜色设为红色并且图例说“&34;点传奇"
dat = data.frame(label = c("A","B","C","D"), group1 = c(1,2,3,5), group2 = c(3,4,5,0), color1 = c("blue","blue","blue","blue") ,
color12 = c("red","red","red","red"))
dat$sizze = ifelse(dat$group2 ==0 ,0, 2 )
ggplot(dat, aes(x = label, y = group1, fill = color1))+
geom_bar(stat="identity") +
geom_point(data = dat, aes(x = label, y = group2, color =color12, size = sizze), shape=15)+
guides(
size = guide_legend(show = FALSE)
)
--->这一行:
dat$sizze = ifelse(dat$group2 ==0 ,0, 3 )
似乎不起作用。我可以将3改为1或5,但情节看起来仍然相同。知道如何让它工作吗?
答案 0 :(得分:2)
使用guides
和scale_*_manual
:
p1 <- ggplot(dat, aes(x = label, y = group1, fill = color1))+
geom_bar(stat="identity") +
geom_point(data = dat, aes(x = label, y = group2, color = color12, size = sizze), shape=15)
p1 +
guides(size = FALSE)+
scale_fill_manual(values = c('blue' = 'blue'),
name = 'bar legend')+
scale_colour_manual(values = c('red' = 'red'),
name = 'point legend')