绘制多个变量进行比较
Plot multiple variables to compare
在比较以下数据的不同参数时绘制多个变量的最佳方法是什么
df1<-data.frame(
Year=sample(2016:2018,100,replace = T),
Month=sample(month.abb,100,replace = T),
category1=sample(letters[1:6],100,replace = T),
catergory2=sample(LETTERS[8:16],100,replace = T),
lic=sample(c("P","F","T"),100,replace = T),
count=sample(1:1000,100,replace = T)
)
我在之前的question/thread中使用了堆叠条形图,想实现上面的。
ggplot(df1,aes(Year,count,fill=factor(lic)))
+geom_bar(stat = "identity",position = "stack")
+facet_grid(~category1)
将 facet_grid(~category1)
替换为 facet_grid(category1~Month)
可能正是您要查找的内容:
在比较以下数据的不同参数时绘制多个变量的最佳方法是什么
df1<-data.frame(
Year=sample(2016:2018,100,replace = T),
Month=sample(month.abb,100,replace = T),
category1=sample(letters[1:6],100,replace = T),
catergory2=sample(LETTERS[8:16],100,replace = T),
lic=sample(c("P","F","T"),100,replace = T),
count=sample(1:1000,100,replace = T)
)
我在之前的question/thread中使用了堆叠条形图,想实现上面的。
ggplot(df1,aes(Year,count,fill=factor(lic)))
+geom_bar(stat = "identity",position = "stack")
+facet_grid(~category1)
将 facet_grid(~category1)
替换为 facet_grid(category1~Month)
可能正是您要查找的内容: