我正在尝试在ggplot2上添加图例。
当我使用以下代码时,我得到以下图。
ggplot() +
geom_bar(data = profitCountries,aes(y = (revenue),x = residence),stat="identity",fill="darkgreen",color = "black") +
geom_bar(data = profitCountries,aes(y = -(total_spend),fill="red",color = "black") +
geom_line(data = profitCountries,aes(y = total_profit,x = residence,group = 1),size = 1.5,color = "blue" ) +
scale_y_continuous(breaks = seq(-500000,500000,100000),limits=c(-500000,500000) ) +
xlab('Countries') + ggtitle('Campaign spending and revenue by countries') +
ylab('Campaign spending Revenue') + theme_grey()
根据其他帖子的建议,我在color
内添加了aes()
。当我尝试使用以下代码进行操作时,得到以下图表。
ggplot() +
geom_bar(data = profitCountries,fill="darkgreen"),fill="red"),group = 1,color = "blue"),size = 2 ) +
scale_y_continuous(breaks = seq(-500000,500000) ) +
xlab('Countries') + ggtitle('Campaign spending and revenue by countries') +
ylab('Campaign spending Revenue') + theme_grey()
在第二个图中,颜色改变,并创建了两个图例。反正有解决办法吗?