Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 从具有条件的熔化数据帧中,在同一层中具有ggplot2的多个箱线图_R_Ggplot2_Boxplot_Melt - Fatal编程技术网

R 从具有条件的熔化数据帧中,在同一层中具有ggplot2的多个箱线图

R 从具有条件的熔化数据帧中,在同一层中具有ggplot2的多个箱线图,r,ggplot2,boxplot,melt,R,Ggplot2,Boxplot,Melt,我有一些数据[在一个.txt文件中]读入一个数据框 mydf <- read.table("data.txt", header=T,sep="\t") 但最终的情节如下所示 但是,我需要的是,在同一个绘图层中,仅将x的正值显示为单个长方体绘图。有人能建议我需要在上面的代码中修改什么才能得到正确的输出吗,谢谢。plt\u bx 0),aes(x=ID1,y=value,color=cols))+geom\u boxplot() plt_bx <- ggplot(subset(df_

我有一些数据[在一个.txt文件中]读入一个数据框

mydf <- read.table("data.txt", header=T,sep="\t")
但最终的情节如下所示

但是,我需要的是,在同一个绘图层中,仅将x的正值显示为单个长方体绘图。有人能建议我需要在上面的代码中修改什么才能得到正确的输出吗,谢谢。

plt\u bx 0),aes(x=ID1,y=value,color=cols))+geom\u boxplot()
plt_bx <- ggplot(subset(df_mlt, value > 0), aes(x=ID1,y=value, color=cols)) + geom_boxplot()
您需要对数据帧进行子集,以删除不需要的值。现在您正在绘制
value>0
,该值为真或假,而不是只绘制大于0的值的箱线图。

plt\u bx 0)、aes(x=ID1,y=value,color=cols))+geom\u箱线图()

您需要对数据帧进行子集,以删除不需要的值。现在您正在绘制
value>0
,该值为TRUE或FALSE,而不是只绘制大于0的值的箱线图。

根据@BrodieG的建议,下面的代码段生成如下图

plt_bx <- ggplot(subset(df_mlt, value > 0), aes(x=ID1,y=value,group=ID1)) + 
  geom_boxplot(aes(color=ID1),outlier.colour="orangered", outlier.size=3) +
  scale_y_log10(labels = trans_format("log10", math_format(10^.x))) +
  theme_bw() +
  theme(legend.text=element_text(size=14), legend.title=element_text(size=14))+
  theme(axis.text=element_text(size=26)) +
  theme(axis.title=element_text(size=22,face="bold")) +
  labs(x = "x", y = "y", colour="Values") +
  annotation_logticks(sides = "rl")
plt_bx
plt <- ggplot(subset(df_mlt, value > 0), aes(x=ID1,y=value)) + 
  geom_boxplot(aes(color=factor(ID1))) +
  scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x))) +
  theme_bw() +
  theme(legend.text=element_text(size=14), legend.title=element_text(size=14))+
  theme(axis.text=element_text(size=20)) +
  theme(axis.title=element_text(size=20,face="bold")) +
  labs(x = "x", y = "y",colour="legend" ) +
  annotation_logticks(sides = "rl") +
  theme(panel.grid.minor = element_blank()) +
  guides(title.hjust=0.5) +
  theme(plot.margin=unit(c(0,1,0,0),"mm")) 
plt
plt_bx 0),aes(x=ID1,y=value,group=ID1))+
geom_箱线图(aes(颜色=ID1),outlier.color=“橙色”,outlier.size=3)+
刻度为log10(标签=转换格式(“log10”,数学格式(10^.x)))+
主题_bw()+
主题(legend.text=元素\文本(大小=14),legend.title=元素\文本(大小=14))+
主题(axis.text=element\u text(size=26))+
主题(axis.title=element\u text(size=22,face=“bold”))+
实验室(x=“x”,y=“y”,color=“value”)+
注释_logticks(sides=“rl”)
plt_bx

根据@BrodieG的建议,下面的代码将生成如下图:

plt_bx <- ggplot(subset(df_mlt, value > 0), aes(x=ID1,y=value,group=ID1)) + 
  geom_boxplot(aes(color=ID1),outlier.colour="orangered", outlier.size=3) +
  scale_y_log10(labels = trans_format("log10", math_format(10^.x))) +
  theme_bw() +
  theme(legend.text=element_text(size=14), legend.title=element_text(size=14))+
  theme(axis.text=element_text(size=26)) +
  theme(axis.title=element_text(size=22,face="bold")) +
  labs(x = "x", y = "y", colour="Values") +
  annotation_logticks(sides = "rl")
plt_bx
plt <- ggplot(subset(df_mlt, value > 0), aes(x=ID1,y=value)) + 
  geom_boxplot(aes(color=factor(ID1))) +
  scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x))) +
  theme_bw() +
  theme(legend.text=element_text(size=14), legend.title=element_text(size=14))+
  theme(axis.text=element_text(size=20)) +
  theme(axis.title=element_text(size=20,face="bold")) +
  labs(x = "x", y = "y",colour="legend" ) +
  annotation_logticks(sides = "rl") +
  theme(panel.grid.minor = element_blank()) +
  guides(title.hjust=0.5) +
  theme(plot.margin=unit(c(0,1,0,0),"mm")) 
plt
plt_bx 0),aes(x=ID1,y=value,group=ID1))+
geom_箱线图(aes(颜色=ID1),outlier.color=“橙色”,outlier.size=3)+
刻度为log10(标签=转换格式(“log10”,数学格式(10^.x)))+
主题_bw()+
主题(legend.text=元素\文本(大小=14),legend.title=元素\文本(大小=14))+
主题(axis.text=element\u text(size=26))+
主题(axis.title=element\u text(size=22,face=“bold”))+
实验室(x=“x”,y=“y”,color=“value”)+
注释_logticks(sides=“rl”)
plt_bx

我改进了我的答案,如果aes中的颜色被指定为数据帧id的一个因子,则箱线图的轮廓将显示不同的颜色。i、 例如,
geom_箱线图(aes(颜色=系数(ID1))

以下代码生成如下图:

plt_bx <- ggplot(subset(df_mlt, value > 0), aes(x=ID1,y=value,group=ID1)) + 
  geom_boxplot(aes(color=ID1),outlier.colour="orangered", outlier.size=3) +
  scale_y_log10(labels = trans_format("log10", math_format(10^.x))) +
  theme_bw() +
  theme(legend.text=element_text(size=14), legend.title=element_text(size=14))+
  theme(axis.text=element_text(size=26)) +
  theme(axis.title=element_text(size=22,face="bold")) +
  labs(x = "x", y = "y", colour="Values") +
  annotation_logticks(sides = "rl")
plt_bx
plt <- ggplot(subset(df_mlt, value > 0), aes(x=ID1,y=value)) + 
  geom_boxplot(aes(color=factor(ID1))) +
  scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x))) +
  theme_bw() +
  theme(legend.text=element_text(size=14), legend.title=element_text(size=14))+
  theme(axis.text=element_text(size=20)) +
  theme(axis.title=element_text(size=20,face="bold")) +
  labs(x = "x", y = "y",colour="legend" ) +
  annotation_logticks(sides = "rl") +
  theme(panel.grid.minor = element_blank()) +
  guides(title.hjust=0.5) +
  theme(plot.margin=unit(c(0,1,0,0),"mm")) 
plt
plt0),aes(x=ID1,y=value))+
geom_箱线图(aes(颜色=系数(ID1)))+
标度=log10(分段=trans\u分段(“log10”,函数(x)10^x),标签=trans\u格式(“log10”,数学格式(10^.x)))+
主题_bw()+
主题(legend.text=元素\文本(大小=14),legend.title=元素\文本(大小=14))+
主题(axis.text=element\u text(大小=20))+
主题(axis.title=元素\文本(大小=20,face=“bold”))+
实验室(x=“x”,y=“y”,color=“legend”)+
注释_logticks(sides=“rl”)+
主题(panel.grid.minor=element\u blank())+
指南(title.hjust=0.5)+
主题(绘图页边距=单位(c(0,1,0,0),“mm”))
plt

我改进了我的答案,如果aes中的颜色被指定为数据帧id的一个因子,则箱线图的轮廓将显示不同的颜色。i、 例如,
geom_箱线图(aes(颜色=系数(ID1))

以下代码生成如下图:

plt_bx <- ggplot(subset(df_mlt, value > 0), aes(x=ID1,y=value,group=ID1)) + 
  geom_boxplot(aes(color=ID1),outlier.colour="orangered", outlier.size=3) +
  scale_y_log10(labels = trans_format("log10", math_format(10^.x))) +
  theme_bw() +
  theme(legend.text=element_text(size=14), legend.title=element_text(size=14))+
  theme(axis.text=element_text(size=26)) +
  theme(axis.title=element_text(size=22,face="bold")) +
  labs(x = "x", y = "y", colour="Values") +
  annotation_logticks(sides = "rl")
plt_bx
plt <- ggplot(subset(df_mlt, value > 0), aes(x=ID1,y=value)) + 
  geom_boxplot(aes(color=factor(ID1))) +
  scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x))) +
  theme_bw() +
  theme(legend.text=element_text(size=14), legend.title=element_text(size=14))+
  theme(axis.text=element_text(size=20)) +
  theme(axis.title=element_text(size=20,face="bold")) +
  labs(x = "x", y = "y",colour="legend" ) +
  annotation_logticks(sides = "rl") +
  theme(panel.grid.minor = element_blank()) +
  guides(title.hjust=0.5) +
  theme(plot.margin=unit(c(0,1,0,0),"mm")) 
plt
plt0),aes(x=ID1,y=value))+
geom_箱线图(aes(颜色=系数(ID1)))+
标度=log10(分段=trans\u分段(“log10”,函数(x)10^x),标签=trans\u格式(“log10”,数学格式(10^.x)))+
主题_bw()+
主题(legend.text=元素\文本(大小=14),legend.title=元素\文本(大小=14))+
主题(axis.text=element\u text(大小=20))+
主题(axis.title=元素\文本(大小=20,face=“bold”))+
实验室(x=“x”,y=“y”,color=“legend”)+
注释_logticks(sides=“rl”)+
主题(panel.grid.minor=element\u blank())+
指南(title.hjust=0.5)+
主题(绘图页边距=单位(c(0,1,0,0),“mm”))
plt

谢谢你的建议。在子集中使用该条件将删除负值。我想为每个x变量ID'显示单独的箱线图s@Amm,尝试将
group=ID1
添加到
aes
,但如果没有数据,则很难更具体。如果您发布数据代表部分的
dput
,我可以给您确切的命令。我在我的question@Amm,我想要一个
dput
。我的Excel认为您的文件可疑。@嗯,正如我前面提到的,如果您使用的是
color=cols
,并且
cols
没有指定实际的颜色,而只是一个组,并且
cols
中的组与
ID1
中的组相同,那么您不需要
group
,您可以使用
color=cols
。如果不满足此处描述的条件,则您不能使用
cols
对箱线图进行着色,至少不能通过
aes
进行着色。谢谢您的建议。在子集中使用该条件将删除负值。我想为每个x变量ID'显示单独的箱线图s@Amm,尝试将
group=ID1
添加到
aes
,但如果没有数据,则很难更具体。如果您发布数据代表部分的
dput
,我可以给您确切的命令。我在我的question@Amm,我想要一个
dput
。我的Excel认为您的文件可疑。@嗯,正如我前面提到的,如果您使用的是
color=cols
,并且
cols
没有指定实际的颜色,而只是一个组,并且
cols
中的组与
ID1
中的组相同,那么您不需要
group
,您可以使用
color=cols
。如果不满足此处描述的条件,则不能使用
cols
为箱线图上色,至少不能通过
aes