使用下面的代码,我创建了一个哑铃图表.
f <- ggplot(Brewers_PA, aes(x=PA.2015, xend=PA.2016, y=Name))
f + geom_dumbbell(colour = "darkblue", point.colour.l = "darkred", point.colour.r = "darkBlue", point.size.l = 2.5, point.size.r = 2.5) +
theme(plot.background=element_rect(fill = "grey93", colour = "grey93")) +
theme(plot.title=element_text(size = 11, face = "bold", hjust = 0)) +
theme(axis.text.x=element_text(size = 8)) +
theme(axis.text.y=element_text(size = 8)) +
theme(axis.title.x=element_text(size = 9)) +
theme(axis.title.y=element_text(size=9)) + ylab("") + xlab("Plate Appearance") +
ggtitle("Brewers Change in Plate Appearance 2015-2016")
Run Code Online (Sandbox Code Playgroud)
由于本教程,我能够做到这一点.https://www.r-bloggers.com/beating-lollipops-into-dumbbells/
唯一的问题是我想为此添加一个图例,但我不知道如何.有人知道吗?所有帮助表示赞赏.
我基本上会喜欢传说中的颜色.所以,"darkblue"= 2016(PA.2016),"darkred"= 2015(PA.2015).我想添加一张图片,但由于某种原因它不会起作用.
这是我创建的数据框:
Name PA.2015 PA.2016
1 Jonathan Villar …Run Code Online (Sandbox Code Playgroud)