我想绘制一个多面的 ggplot2 点图。x 轴是连续的,y 轴是动物列表。根据饮食行为绘制和刻面两个变量。
y 轴是自由比例的,因为每只动物只出现在一个饮食行为类别中。
library(ggplot2)
# First clean up the data set:
msleep.noNA <- msleep[!is.na(msleep$vore),]
msleep.noNA.red <- msleep.noNA[c(1,3,6,7)]
msleep.noNA.red <- msleep.noNA.red[!is.na(msleep.noNA.red[4]),]
msleep.noNA.red <- melt(msleep.noNA.red)
pg <- ggplot(msleep.noNA.red, aes(value, name, colour = variable)) +
geom_point() +
facet_grid(vore ~ ., scale="free_y", space = "free_y")
pg
# Try to reverse order of the y axis:
pg + scale_y_reverse()
# Not possible because its a factor, but it's not classified as such:
class(msleep.noNA.red$name)
有人知道如何在每个子图中按字母顺序排列动物名称列表吗?