R 我正在使用ggplot在x轴上绘制年份图,并按位置填充
我想看看哪一年出现了什么职位。某些ID可能不包含某些位置R 我正在使用ggplot在x轴上绘制年份图,并按位置填充,r,ggplot2,R,Ggplot2,我想看看哪一年出现了什么职位。某些ID可能不包含某些位置 ID YEAR POS 144 2017 10 144 2017 12 144 2017 18 144 2017 15 144 2017 163 144 2017 200 AB01 2018 10 AB01 2018 15 AB01 2018 18 这就是我尝试过的 ggplot(data1) + geom_bar(aes(ID, fill=PO
ID YEAR POS
144 2017 10
144 2017 12
144 2017 18
144 2017 15
144 2017 163
144 2017 200
AB01 2018 10
AB01 2018 15
AB01 2018 18
这就是我尝试过的
ggplot(data1) + geom_bar(aes(ID, fill=POS)) + facet_wrap(~ data1$YEAR) + labs(x="Year", y= "Number ", fill = "position", Title= "Pos plot") + theme(text = element_text(size = 15, color = "Black"))
也许这就是你要找的
library(ggplot2)
ggplot(data1, aes(x = ID, y=1, fill = as.factor(POS))) +
geom_bar(stat = "identity", position = "stack") +
facet_wrap(~ data1$YEAR) +
labs(x="Year", y= "Number ", fill = "position", Title= "Pos plot") +
theme(text = element_text(size = 15, color = "Black"))
您是否有一个您希望看到的情节示例?谢谢@Ian Campbell。我添加了facet_wrap(~data1$Year,ncol=1,scale=“free”)来删除当年不存在的ID。我想知道是否也有办法在绘图中包含缺失的值。示例为AB01绘制所有6个位置,并使用白色表示缺少的数据。我不完全确定您的意思。也许可以打开一个新问题,模拟您在mspaint、preview或gimp中所寻找的内容。