我遇到了问题,无法在StackOverflow上找到答案。
无论我做什么,传说都不想出现在我的情节中。我有一个简单的数据框:
'data.frame': 22 obs. of 8 variables:
$ fan_page_id : Factor w/ 11 levels "Brand1",..: 10 10 8 8 4 4 3 3 9 9 ...
$ is_paid : Factor w/ 2 levels "niesponsorowane",..: 1 2 1 2 1 2 1 2 1 2 ...
$ all_activity : num 55 225 45 354 41 ...
$ reach : num 13300 13300 24200 24200 62000 62000 52700 52700 11300 11300 ...
$ color_main : chr "#34445b" "#34445b" "#34445b" "#34445b" ...
$ color_brighter: chr "#f8bd99" "#f8bd99" "#f8bd99" "#f8bd99" ...
$ color : chr "#34445b" "#ef5a00" "#34445b" "#ef5a00" ...
$ color2 : chr "#8B9EBC" "#f8bd99" "#8B9EBC" "#f8bd99" ...
我想用这段代码绘制图表:
plot = ggplot(data=dane, aes(x=fan_page_id, y=all_activity), fill = all_activity) +
geom_bar(data = dane, aes(x = fan_page_id, y = (reach)/50, group = dane$is_paid), fill = dane$color2, stat="identity", position = position_dodge(0.9)) +
geom_bar(data = dane, aes(x = fan_page_id, y = all_activity, group = dane$is_paid), fill = dane$color, stat="identity", position = position_dodge(0.9)) +
scale_fill_manual(values=c('black','orange'), labels=c(sponsored_label,non_sponsored_label), breaks = c(sponsored_label,non_sponsored_label))+
geom_text(data=dane, aes(x=fan_page_id, y=(max(reach)*.0011), label=round(all_activity),
group = dane$is_paid),
size=12,
family='Lato Black',
color='white',
hjust = 0.28,
position = position_dodge(0.9))+
geom_text(data=dane, aes(x=fan_page_id, y=reach/50, label=round(reach)),
size=12,
family='Lato Black',
color=dane$color_main,
hjust = -0.2,
position = position_dodge(0.9))+
coord_flip()+
ylim(c(-(max(dane$reach)*.00001), max(dane$reach/50)+0.2*max(dane$reach/50)))+
myTheme+
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_blank(),
axis.ticks = element_blank(),
legend.position = "bottom", legend.direction = "horizontal")+
annotate("text", x = nrow(dane)/2, y = max(dane$all_activity)*0.19, label = 'Test1', hjust = 1, family = "Lato Black", size = 6, colour = so_orange)+
#annotate("text", x = nrow(dane)+0.13, y = dane_plot$coactive[2], label = coac.plot@labels$middle, hjust = 0, family = "Lato Black", size = 6, colour = "#000000")+
annotate("text", x = nrow(dane)/2, y = max(dane$all_activity)*0.5, label = 'Test2', hjust = 1, family = "Lato Black", size = 6, colour = '#f8bd99')
file = ps('activities2.png')
png(file, 1400, 1000)
print(plot)
dev.off()
myTheme也很好看:
$ legend.key.size :Class 'unit' atomic [1:1] 10
.. ..- attr(*, "valid.unit")= int 7
.. ..- attr(*, "unit")= chr "mm"
$ legend.text :List of 11
..$ family : chr "Lato Light"
..$ face : NULL
..$ colour : chr "black"
..$ size : num 24
..$ hjust : NULL
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi FALSE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ legend.title : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ legend.position : chr "right"
$ legend.direction: chr "vertical"
嗯,这是新的ggplot 2,我发现了一些scale_fill_manual的问题,我之前用它来获取图例。为了在情节上有传说,我该怎么做?