绘制两个分类因子对R中无序多项式变量的影响
利用这些,我想同时绘制两个分类因子对多项式变量的影响。这是人工智能所能做到的:绘制两个分类因子对R中无序多项式变量的影响,r,ggplot2,rstudio,multinomial,R,Ggplot2,Rstudio,Multinomial,利用这些,我想同时绘制两个分类因子对多项式变量的影响。这是人工智能所能做到的: require(ggplot2) df=read.csv("example.csv") ggplot(df,aes(x=treatment , y=option, group=morph)) + geom_bar(stat = "identity")+ scale_colour_brewer(palette="Set1")+ ylab("Escape strategy")+ xlab("Treatment
require(ggplot2)
df=read.csv("example.csv")
ggplot(df,aes(x=treatment , y=option, group=morph)) +
geom_bar(stat = "identity")+
scale_colour_brewer(palette="Set1")+
ylab("Escape strategy")+
xlab("Treatment")
我在寻找一个图形,其中每个处理有两个条,一个用于每个变形,在每个条中,每个选项的频率显示为颜色,并与实心条的长度成比例
提前感谢。这里有一种方法可以显示三个分类变量的条形图。我添加了一个用于再现性的最小示例数据集(基于您发布的数据)
太好了!但是,我现在无法更改响应变量的名称。@Aguscamacho,我不确定我是否理解这个问题。您仍然可以添加
+ylab(“转义策略”)
来更改y轴标签。另外,您可能想尝试geom_条(position=“stack”)
和geom_条(position=“dodge”)
来显示y轴上的计数(而不是分数)。我不明白为什么昨天不能,今天也可以。谢谢你的其他建议!
# Small example data set.
dat = read.table(header=TRUE,
text="option treatment morph
burrow a c
hide a c
hide a c
hide a c
run a c
run a c
burrow a d
burrow a d
burrow a d
hide a d
run a d
run b c
run b c
run b c
burrow b c
hide b c
burrow b d
burrow b d
hide b d
run b d")
library(ggplot2)
p1 = ggplot(dat, aes(x=morph, fill=option)) +
geom_bar(position="fill") +
scale_fill_brewer(palette="Set1") +
facet_grid(. ~ treatment, labeller=label_both)
ggsave("bar_plot.png", p1, height=6, width=6, dpi=150)