Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.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 使用ggplot(按面或颜色编码因子绘制)在同一图形上绘制大量因子的百分比变化_R_Graphics_Ggplot2_Facet_Facet Wrap - Fatal编程技术网

R 使用ggplot(按面或颜色编码因子绘制)在同一图形上绘制大量因子的百分比变化

R 使用ggplot(按面或颜色编码因子绘制)在同一图形上绘制大量因子的百分比变化,r,graphics,ggplot2,facet,facet-wrap,R,Graphics,Ggplot2,Facet,Facet Wrap,下面是我正在使用的代码示例 x<-as.factor(rep(c("tree_mean","tree_qmean","tree_skew"),3)) factor<-c(rep("mfn2_burned_99",3),rep("mfna_burned_5_7",3),rep("mfna_burned_5_7_10_12",3))) y<-c(0.336457409,-0.347422910,-0.318945621,1.494109367, 0.003578698,-0.019

下面是我正在使用的代码示例

x<-as.factor(rep(c("tree_mean","tree_qmean","tree_skew"),3))
factor<-c(rep("mfn2_burned_99",3),rep("mfna_burned_5_7",3),rep("mfna_burned_5_7_10_12",3)))
y<-c(0.336457409,-0.347422910,-0.318945621,1.494109367, 0.003578698,-0.019985780,-0.484171146, 0.611589217,-0.322292664)
dat<-as.data.frame(cbind(x,factor,y))
head(dat)
       x               factor          y
tree_mean      mfn2_burned_99        -0.3364574
tree_qmean     mfn2_burned_99        -0.3474229
tree_skew      mfn2_burned_99        -0.3189456
tree_mean      mfna_burned_5_7       -0.8269814
tree_qmean     mfna_burned_5_7       -0.8088810
tree_skew      mfna_burned_5_7       -2.5429226
tree_mean      mfna_burned_5_7_10_12 -0.8601206
tree_qmean     mfna_burned_5_7_10_12 -0.8474920
tree_skew      mfna_burned_5_7_10_12 -2.9854178
当我有三个因素(忽略*)时,这就很好了:我有一个重要性列,我已经删除了它

示例如下:

然而,我总共有8个因子,而刻面使绘图变得模糊,因此每个x值与零的距离变得非常扭曲

下面的例子

所以,我的问题是:考虑到我在ggplot中使用了大量的x值和因子,使用刻面或按因子的颜色编码,有什么更好的方法来编码/呈现这个图


我会非常开放地按照因子为x的每个距离进行颜色编码,而不是刻面,但我一直在拼命想办法在ggplot中实现这一点(对于ggplot来说非常新),因此我还不能说这是否会使图形更易于解释。

您注意到的一个选项是按系数为点和/或线范围着色。然后,您可以使用
位置减淡
在x轴上稍微移动点

例如:

ggplot(dat, aes(color = factor)) +
    geom_point(aes(x=x,y=y),shape=1,size=3, position = position_dodge(width  = 0.5)+
    geom_linerange(aes(x=x,ymin=0,ymax=y), position = position_dodge(width =0.5))+
    geom_hline(yintercept=0)

我认为这仍然是困难的,因为有很多因素,但有8个因素,它可能适合你的目的。

Jraab,许多泰克人,谢谢你的回答。道奇的位置成功了!
ggplot(dat, aes(color = factor)) +
    geom_point(aes(x=x,y=y),shape=1,size=3, position = position_dodge(width  = 0.5)+
    geom_linerange(aes(x=x,ymin=0,ymax=y), position = position_dodge(width =0.5))+
    geom_hline(yintercept=0)