所以我使用 ggplot2 来绘制条形图和点。我目前得到这个:
正如您所看到的,这些条很好地分开并以所需的颜色着色。然而,我的观点都是无色的,并且堆叠在彼此之上。我希望这些点在他们指定的栏上方并且颜色相同。
#Add bars
A <- A + geom_col(aes(y = w1, fill = factor(Species1)),
position = position_dodge(preserve = 'single'))
#Add colors
A <- A + scale_fill_manual(values = c("A. pelagicus"= "skyblue1","A. superciliosus"="dodgerblue","A. vulpinus"="midnightblue","Alopias sp."="black"))
#Add points
A <- A + geom_point(aes(y = f1/2.5),
shape= 24,
size = 3,
fill = factor(Species1),
position = position_dodge(preserve = 'single'))
#change x and y axis range
A <- A + scale_x_continuous(breaks = c(2000:2020), limits = c(2016,2019))
A <- A + expand_limits(y=c(0,150))
# now adding the secondary axis, following the example in the help file ?scale_y_continuous
# and, very important, reverting the above transformation
A <- A + scale_y_continuous(sec.axis = sec_axis(~.*2.5, name = " "))
# modifying axis and title
A <- A + labs(y = " ",
x = " ")
A <- A + theme(plot.title = element_text(size = rel(4)))
A <- A + theme(axis.text.x = element_text(face="bold", size=14, angle=45),
axis.text.y = element_text(face="bold", size=14))
#A <- A + theme(legend.title = element_blank(),legend.position = "none")
#Print plot
A
当我运行此代码时,我收到以下错误:
错误:未知颜色名称:A. pelagcus 另外:警告消息:1:未定义宽度。设置为position_dodge(width = ?)
2:在 max(table(panel$xmin)) 中:max 没有非缺失参数;返回-Inf
我已经尝试了几件事,但我不知道它是否适用于 geom_col 而不适用于 geom_points。
提前致谢