我有以下数据集:
Type <- c("Type 2", "Type 2", "Type 3", "Type 3", "Type 3", "Type 2", "Type 2", "Type 3", "Type 1", "Type 2", "Type 2", "Type 3", "Type 3", "Type 1", "Type 2", "Type 3", "Type 3", "Type 1", "Type 2", "Type 1", "Type 3", "Type 2", "Type 2", "Type 2", "Type 3", "Type 2", "Type 3", "Type 3", "Type 3", "Type 2", "Type 3", "Type 3", "Type 1", "Type 1", "Type 3", "Type 2", "Type 3", "Type 2", "Type 2", "Type 1", "Type 2", "Type 1")
Group <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP")
Abundance <- c(79, 76, 66, 58, 51, 36, 35, 29, 26, 25, 24, 21, 9, 8, 8, 6, 6, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
Abundance_data <- data.frame (Type, Group, Abundance)
我使用此代码制作了一个充满群体的情节:
# Create a vector to specify the colour and shape for each type
colours_by_type <- c("Type 1"="orange", "Type 2"="chartreuse4", "Type 3"="brown2")
# Reorder the data so that it goes from largest to smallest
Abundance_data_reordered <- transform (Abundance_data, Group = reorder(Group, order(Abundance, decreasing=TRUE))) # The data here is ordered already but my real data is not
# Create an ordered barplot
abundance_plot <- ggplot(data=Abundance_data_reordered, aes(x=Group, y=Abundance)) +
geom_bar(stat = "identity", aes(fill = Type))+
theme(axis.text.x = element_text(angle=90, hjust=1, vjust=0.5))+
scale_fill_manual(values = colours_by_type)+
theme(axis.title.x=element_blank())+
labs(y="Abundance")+ #
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"))
abundance_plot
这产生了以下情节:
我想为此添加一条曲线。我认为指数曲线是最合适的,但我无法弄清楚如何做到这一点,因为我看到的所有例子都有x轴上的数值数据。
有没有办法让回归曲线或指数曲线适合我的情节?