正如Markus建议的那样,您需要通过添加数据将数据转换为长格式。使用 melt 功能来自 reshape2 。它应该看起来像这样:
melt
reshape2
plotdf <- as.data.frame(t(df)) plotdf$var <- rownames(plotdf) plotdf <- melt(plotdf[-c(1),], id.vars = "var") print(ggplot(plotdf, aes(value, variable, colour = var)) + geom_point()+ scale_y_discrete(breaks=seq(0, 2, by = 0.5)) + ggtitle("Gamma distribution density function") +ylab("density")+ xlab("x")+ theme(legend.position = "bottom")+ guides(fill = guide_legend(reverse=TRUE)))
输出:
可以使用其他格式更多地格式化图 ggplot 特征。 检查一下: 如何按条形图融合R data.frame和plot group
ggplot