R中有没有办法在不将数据从宽格式转换为长格式的情况下绘制分组的点图?
我正在使用一个看起来像:
df = data_frame(
A=c(sample(0:2,size=50,replace=TRUE)),
A1=c(sample(0:50,size=50,replace=TRUE)),
A2=c(sample(0:50,size=50,replace=TRUE)))
我正在尝试生成A1和A1的分组点图,例如
: “ alt =”分组图”>
为了产生此功能,我使用以下代码将数据从宽格式转换为长格式,然后
library(reshape2)
df2 <- melt(df, id.vars=c("A"))
我正在尝试工作出去如何绘制等效图而不转换格式。我当前的代码是:
library(ggplot2)
ggplot(df,aes(x=as.factor(A)))+
xlab("A") +
ylab("Score") +
geom_dotplot (aes(y=A1), binaxis="y",binwidth=1, stackdir = "center",fill="#5ec962",colour="#5ec962") +
stat_summary(aes(y=A1),fun = median, fun.min = median, fun.max = median, geom = "crossbar", width = 0.2,colour="#5ec962") +
geom_dotplot (aes(y=A2), binaxis="y",binwidth=1, stackdir = "center",fill="#3b528b",colour="#3b528b") +
stat_summary(aes(y=A2),fun = median, fun.min = median, fun.max = median, geom = "crossbar", width = 0.2,colour="#3b528b") +
theme_classic()
这两个组彼此之间的顶部是:
是否有一种产生的方法像第一组一样的图形,而没有转换格式?我打算查看多次比较,理想情况下将不继续进行转换。
谢谢。
I am using an r data frame which looks something like:
df = data_frame(
A=c(sample(0:2,size=50,replace=TRUE)),
A1=c(sample(0:50,size=50,replace=TRUE)),
A2=c(sample(0:50,size=50,replace=TRUE)))
I am trying to produce a grouped dot plot of A1 and A1, grouped by A, e.g:
To produce this I've converted the data from wide to long format using the below code and then utlised position_dodge
library(reshape2)
df2 <- melt(df, id.vars=c("A"))
I'm trying to work out how to draw the equivalent graph without converting the format. My current code is:
library(ggplot2)
ggplot(df,aes(x=as.factor(A)))+
xlab("A") +
ylab("Score") +
geom_dotplot (aes(y=A1), binaxis="y",binwidth=1, stackdir = "center",fill="#5ec962",colour="#5ec962") +
stat_summary(aes(y=A1),fun = median, fun.min = median, fun.max = median, geom = "crossbar", width = 0.2,colour="#5ec962") +
geom_dotplot (aes(y=A2), binaxis="y",binwidth=1, stackdir = "center",fill="#3b528b",colour="#3b528b") +
stat_summary(aes(y=A2),fun = median, fun.min = median, fun.max = median, geom = "crossbar", width = 0.2,colour="#3b528b") +
theme_classic()
This has the two groups on top of each other like this:
Is there a way to produce a graph like the first one with the groups side by side without converting the format? I'm planning to look at multiple comparison and would ideally not keep doing conversions.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论