嘿,
我正在尝试在 x 轴上添加深度范围的信息(1)或(2)在图形的堆栈条顶部(或类似的东西)。请参阅下面的图片。
带有标签: 在此处输入图像描述
(1) 不知道怎么做。
(2) 为了在堆积条的顶部绘制信息,我首先创建了变量:
depth_int <- c("5-200 m", "5-181 m", "5-200 m", "5-200 m", "5-155 m", "5-200 m", "5-200 m",
"5-90 m", "10-60 m", "10-90 m", "10-30 m", "20-90 m", "0.5-30 m", "0.5-90 m", "0.5-90 m")
并在我的 ggplot() 上使用此函数:
geom_text(aes(label = depth_int), hjust = 0, position = "stack")
我收到此错误:
Error: Aesthetics must be either length 1 or the same as the data (164): label
(我猜是因为堆积条是分类群的组合,然后您不能在每个站点的条顶部仅绘制 1 个值(例如,P1)。
-
这是我的脚本:
ggplot(df, aes(x=locationID, fill=class, y = V1))+
geom_bar(stat="identity", position = "stack", width = 0.9)+
facet_grid(. ~ expedition, scales="free_x") +
#scale_fill_manual(values = default_colors, labels= c("","","")) #default_colors<-c("#F8766D", "#00BA38", "#619CFF")
# change the label names in the legend
labs(title = "Taxa abundance per depth integrated", fill = "Taxa",
x= bquote('Stations'),
y= bquote('Abundance'~(cells~m^-3)))+
theme_minimal()+
theme(panel.grid.major.y = element_line(size = 0.5, linetype = 'solid',
colour = "grey75"),
panel.grid.minor.y = element_line(size = 0.5, linetype = 'solid',
colour = "grey75"),
panel.grid.major.x = element_blank(),
panel.background = element_rect(fill = "white", colour = "grey75"),
axis.text.x = element_text(colour="black",size=7),
axis.text.y = element_text(colour="black",size=10),
axis.title.x = element_text(colour="black",size=10),
axis.title.y = element_text(colour="black",size=10),
plot.title = element_text(colour = "black", size = 10, face = "bold"),
legend.position = "right",
legend.text = element_text(size=10),
legend.title = element_text(size = 11, hjust =0.5, vjust = 3, face = "bold"),
legend.key.size = unit(10,"point"),
legend.spacing.y = unit(-.25,"cm"),
legend.margin=margin(0,5,8,5),
legend.box.margin=margin(-10,10,-3,10),
legend.box.spacing = unit(0.5,"cm"),
plot.margin = margin(2,2,0,0))