Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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_Colors_Scale_Geom Bar - Fatal编程技术网

R ggplot2带有渐变颜色填充和离散值的水平条形图,提供给连续比例

R ggplot2带有渐变颜色填充和离散值的水平条形图,提供给连续比例,r,ggplot2,colors,scale,geom-bar,R,Ggplot2,Colors,Scale,Geom Bar,我正在尝试创建水平条形图,并希望使用颜色渐变填充条形图,最低值为白色,最高值为最暗 首先,我通过follow脚本创建了图1。各栏告知每种物种的频率): 数据: 正如@Z.Lin所写,您应该删除geom_条(stat=“identity”)+,但保留fill=momento: Dataset <- read.table(text = "specie momento M1_sava S1 M1 1.00 S2 M

我正在尝试创建水平条形图,并希望使用颜色渐变填充条形图,最低值为白色,最高值为最暗

首先,我通过follow脚本创建了图1。各栏告知每种物种的频率):

数据:


正如@Z.Lin所写,您应该删除
geom_条(stat=“identity”)+
,但保留
fill=momento

Dataset <- read.table(text = "specie  momento M1_sava
                  S1  M1  1.00
                  S2  M1  0.86
                  S3  M1  1.00
                  S4  M1  1.00
                  S5  M1  1.00
                  S6  M1  0.74
                  S7  M1  0.39
                  S8  M1  0.83
                  S9  M1  0.83
                  S10 M1  0.00
                  S11 M1  0.70
                  S12 M1  0.11
                  S13 M1  1.00
                  S14 M1  0.00
                  S15 M1  0.00
                  S16 M1  0.00
                  S17 M1  0.00
                  S18 M1  0.83
                  S19 M1  0.00
                  S20 M1  0.00
                  S21 M1  0.00
                  S22 M1  0.00
                  S23 M1  0.00
                  S24 M1  0.04
                  S25 M1  0.00
                  S26 M1  0.00
                  S1  M2  0.33
                  S2  M2  0.86
                  S3  M2  0.39
                  S4  M2  0.02
                  S5  M2  0.07
                  S6  M2  0.02
                  S7  M2  0.87
                  S8  M2  0.06
                  S9  M2  0.63
                  S10 M2  0.33
                  S11 M2  0.91
                  S12 M2  0.67
                  S13 M2  0.18
                  S14 M2  0.08
                  S15 M2  0.00
                  S16 M2  0.00
                  S17 M2  0.00
                  S18 M2  0.00
                  S19 M2  0.08
                  S20 M2  0.00
                  S21 M2  0.04
                  S22 M2  0.00
                  S23 M2  0.00
                  S24 M2  0.00
                  S25 M2  0.00
                  S26 M2  0.00
                  S1  M3  0.04
                  S2  M3  0.32
                  S3  M3  0.02
                  S4  M3  0.00
                  S5  M3  0.00
                  S6  M3  0.00
                  S7  M3  0.96
                  S8  M3  0.06
                  S9  M3  0.18
                  S10 M3  0.33
                  S11 M3  0.63
                  S12 M3  1.00
                  S13 M3  0.00
                  S14 M3  0.94
                  S15 M3  0.17
                  S16 M3  0.00
                  S17 M3  0.41
                  S18 M3  0.04
                  S19 M3  0.44
                  S20 M3  0.17
                  S21 M3  0.02
                  S22 M3  0.00
                  S23 M3  0.00
                  S24 M3  0.00
                  S25 M3  0.00
                  S26 M3  0.00
                  S1  M4  0.00
                  S2  M4  0.00
                  S3  M4  0.00
                  S4  M4  0.00
                  S5  M4  0.00
                  S6  M4  0.00
                  S7  M4  0.89
                  S8  M4  0.00
                  S9  M4  0.03
                  S10 M4  0.22
                  S11 M4  0.41
                  S12 M4  0.46
                  S13 M4  0.00
                  S14 M4  0.81
                  S15 M4  0.39
                  S16 M4  0.70
                  S17 M4  0.70
                  S18 M4  0.00
                  S19 M4  0.87
                  S20 M4  0.91
                  S21 M4  0.33
                  S22 M4  0.37
                  S23 M4  0.24
                  S24 M4  0.15
                  S25 M4  0.00
                  S26 M4  0.00", header = T)

library(ggplot2)

ggplot(Dataset, aes(specie, M1_sava, fill = momento)) + 
  facet_wrap(~ momento, nrow = 1) + 
  coord_flip() + 
  geom_col(aes(fill = M1_sava)) + 
  scale_fill_gradient2(low = "white", high = "green") + 
  theme_bw(base_size = 10)  

Dataset尝试从代码中删除
geom_栏(stat=“identity”)+
行。它仍然继承了顶级美学映射
fill=momento
(即离散比例),这与
scale\u fill\u gradient2
(即连续比例)冲突。谢谢你,Z.lin,但是在下面的脚本中会出现错误消息:错误:stat\u count()不能与y美学一起使用。ggplot(数据集,aes(物种,M1#sava))+面#wrap(~momento,nrow=1)+将因子放置在单独的面geom#bar()+#使条协调翻转()+#翻转轴,以便测试名称可以是水平geom#col(aes(fill=M1#sava))+比例#fill#gradient2(low=“white”,high=“green”)+主题#bw(base#size=10)嗨,阿德拉,谢谢你!我确实想要这张图片,但我试过你和@z.lin说的脚本,但没有成功。你是不是用了这个精确的脚本?因为我正在尝试这一个,错误消息仍然出现,并上传数据和库。这是我的完整代码。也许您有一些旧版本的
ggplot2
。尝试更新它。
ggplot(Dataset, aes(specie,M1_sava, fill = momento)) + 
  facet_wrap(~ momento, nrow=1) + # place the factors in separate facets
  geom_bar(stat="identity") +     # make the bars
  coord_flip() +                  # flip the axes so the test names can be horizontal  
  geom_col(aes(fill = M1_sava)) + 
  scale_fill_gradient2(low = "white",high = "green") +
  theme_bw(base_size=10)          # use a black-and-white theme with set font size
specie  momento M1_sava
S1  M1  1,00
S2  M1  0,86
S3  M1  1,00
S4  M1  1,00
S5  M1  1,00
S6  M1  0,74
S7  M1  0,39
S8  M1  0,83
S9  M1  0,83
S10 M1  0,00
S11 M1  0,70
S12 M1  0,11
S13 M1  1,00
S14 M1  0,00
S15 M1  0,00
S16 M1  0,00
S17 M1  0,00
S18 M1  0,83
S19 M1  0,00
S20 M1  0,00
S21 M1  0,00
S22 M1  0,00
S23 M1  0,00
S24 M1  0,04
S25 M1  0,00
S26 M1  0,00
S1  M2  0,33
S2  M2  0,86
S3  M2  0,39
S4  M2  0,02
S5  M2  0,07
S6  M2  0,02
S7  M2  0,87
S8  M2  0,06
S9  M2  0,63
S10 M2  0,33
S11 M2  0,91
S12 M2  0,67
S13 M2  0,18
S14 M2  0,08
S15 M2  0,00
S16 M2  0,00
S17 M2  0,00
S18 M2  0,00
S19 M2  0,08
S20 M2  0,00
S21 M2  0,04
S22 M2  0,00
S23 M2  0,00
S24 M2  0,00
S25 M2  0,00
S26 M2  0,00
S1  M3  0,04
S2  M3  0,32
S3  M3  0,02
S4  M3  0,00
S5  M3  0,00
S6  M3  0,00
S7  M3  0,96
S8  M3  0,06
S9  M3  0,18
S10 M3  0,33
S11 M3  0,63
S12 M3  1,00
S13 M3  0,00
S14 M3  0,94
S15 M3  0,17
S16 M3  0,00
S17 M3  0,41
S18 M3  0,04
S19 M3  0,44
S20 M3  0,17
S21 M3  0,02
S22 M3  0,00
S23 M3  0,00
S24 M3  0,00
S25 M3  0,00
S26 M3  0,00
S1  M4  0,00
S2  M4  0,00
S3  M4  0,00
S4  M4  0,00
S5  M4  0,00
S6  M4  0,00
S7  M4  0,89
S8  M4  0,00
S9  M4  0,03
S10 M4  0,22
S11 M4  0,41
S12 M4  0,46
S13 M4  0,00
S14 M4  0,81
S15 M4  0,39
S16 M4  0,70
S17 M4  0,70
S18 M4  0,00
S19 M4  0,87
S20 M4  0,91
S21 M4  0,33
S22 M4  0,37
S23 M4  0,24
S24 M4  0,15
S25 M4  0,00
S26 M4  0,00
Dataset <- read.table(text = "specie  momento M1_sava
                  S1  M1  1.00
                  S2  M1  0.86
                  S3  M1  1.00
                  S4  M1  1.00
                  S5  M1  1.00
                  S6  M1  0.74
                  S7  M1  0.39
                  S8  M1  0.83
                  S9  M1  0.83
                  S10 M1  0.00
                  S11 M1  0.70
                  S12 M1  0.11
                  S13 M1  1.00
                  S14 M1  0.00
                  S15 M1  0.00
                  S16 M1  0.00
                  S17 M1  0.00
                  S18 M1  0.83
                  S19 M1  0.00
                  S20 M1  0.00
                  S21 M1  0.00
                  S22 M1  0.00
                  S23 M1  0.00
                  S24 M1  0.04
                  S25 M1  0.00
                  S26 M1  0.00
                  S1  M2  0.33
                  S2  M2  0.86
                  S3  M2  0.39
                  S4  M2  0.02
                  S5  M2  0.07
                  S6  M2  0.02
                  S7  M2  0.87
                  S8  M2  0.06
                  S9  M2  0.63
                  S10 M2  0.33
                  S11 M2  0.91
                  S12 M2  0.67
                  S13 M2  0.18
                  S14 M2  0.08
                  S15 M2  0.00
                  S16 M2  0.00
                  S17 M2  0.00
                  S18 M2  0.00
                  S19 M2  0.08
                  S20 M2  0.00
                  S21 M2  0.04
                  S22 M2  0.00
                  S23 M2  0.00
                  S24 M2  0.00
                  S25 M2  0.00
                  S26 M2  0.00
                  S1  M3  0.04
                  S2  M3  0.32
                  S3  M3  0.02
                  S4  M3  0.00
                  S5  M3  0.00
                  S6  M3  0.00
                  S7  M3  0.96
                  S8  M3  0.06
                  S9  M3  0.18
                  S10 M3  0.33
                  S11 M3  0.63
                  S12 M3  1.00
                  S13 M3  0.00
                  S14 M3  0.94
                  S15 M3  0.17
                  S16 M3  0.00
                  S17 M3  0.41
                  S18 M3  0.04
                  S19 M3  0.44
                  S20 M3  0.17
                  S21 M3  0.02
                  S22 M3  0.00
                  S23 M3  0.00
                  S24 M3  0.00
                  S25 M3  0.00
                  S26 M3  0.00
                  S1  M4  0.00
                  S2  M4  0.00
                  S3  M4  0.00
                  S4  M4  0.00
                  S5  M4  0.00
                  S6  M4  0.00
                  S7  M4  0.89
                  S8  M4  0.00
                  S9  M4  0.03
                  S10 M4  0.22
                  S11 M4  0.41
                  S12 M4  0.46
                  S13 M4  0.00
                  S14 M4  0.81
                  S15 M4  0.39
                  S16 M4  0.70
                  S17 M4  0.70
                  S18 M4  0.00
                  S19 M4  0.87
                  S20 M4  0.91
                  S21 M4  0.33
                  S22 M4  0.37
                  S23 M4  0.24
                  S24 M4  0.15
                  S25 M4  0.00
                  S26 M4  0.00", header = T)

library(ggplot2)

ggplot(Dataset, aes(specie, M1_sava, fill = momento)) + 
  facet_wrap(~ momento, nrow = 1) + 
  coord_flip() + 
  geom_col(aes(fill = M1_sava)) + 
  scale_fill_gradient2(low = "white", high = "green") + 
  theme_bw(base_size = 10)