Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.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_Histogram - Fatal编程技术网

如何在R中使用ggplot2创建背靠背直方图?

如何在R中使用ggplot2创建背靠背直方图?,r,ggplot2,histogram,R,Ggplot2,Histogram,我有一个名为TP\u FP的df,希望使用ggplot2基于组列创建一个背对背(镜像)直方图 `TP_FP` Value Group <dbl> <chr> 1 -0.00540 False positive 2 0.331 True positive 3 -1.11 False posi

我有一个名为
TP\u FP
df
,希望使用ggplot2基于组列创建一个背对背(镜像)直方图

 `TP_FP`
           Value        Group        
            <dbl>       <chr>         
         1 -0.00540   False positive
         2  0.331     True positive
         3 -1.11      False positive
         4  1.4365    False positive
         5 -0.586     True positive
         6  1.26      True positive
         7  0.5463    False positive
         8  3.245     False positive
         9 -0.950     False positive
        10 10.4354    True positive
我希望得到一个合并的柱状图,就像底部的柱状图一样

像这样吗

library(tidyverse)
TP_FP <- tribble(~Value, ~Group,        
                -0.00540, "False positive",
                0.331, "True positive",
                -1.11, "False positive",
                1.4365, "False positive",
                -0.586, "True positive",
                1.26, "True positive",
                0.5463, "False positive",
                3.245, "False positive",
                -0.950, "False positive",
                10.4354, "True positive")

ggplot() +
  geom_histogram(data = TP_FP %>% filter(Group == "False positive"),
                 aes(y = -(..density..), x = Value, fill = Group),
                 col = "black", binwidth = 0.1) +
  geom_histogram(data = TP_FP %>% filter(Group == "True positive"),
                 aes(y = ..density.., x = Value, fill = Group),
                 col = "black", binwidth = 0.1) +
  labs(x = "R Ratio", y = "Number of proteins") +
  theme_bw() + theme(legend.position = "right")
库(tidyverse)
TP_FP%过滤器(组=“假阳性”),
aes(y=-(…密度…),x=值,填充=组),
col=“黑色”,binwidth=0.1)+
几何图形直方图(数据=TP\U FP%>%过滤器(组=“真正”),
aes(y=密度,x=值,填充=组),
col=“黑色”,binwidth=0.1)+
实验室(x=“R比率”,y=“蛋白质数量”)+
theme_bw()+主题(legend.position=“right”)

library(tidyverse)
TP_FP <- tribble(~Value, ~Group,        
                -0.00540, "False positive",
                0.331, "True positive",
                -1.11, "False positive",
                1.4365, "False positive",
                -0.586, "True positive",
                1.26, "True positive",
                0.5463, "False positive",
                3.245, "False positive",
                -0.950, "False positive",
                10.4354, "True positive")

ggplot() +
  geom_histogram(data = TP_FP %>% filter(Group == "False positive"),
                 aes(y = -(..density..), x = Value, fill = Group),
                 col = "black", binwidth = 0.1) +
  geom_histogram(data = TP_FP %>% filter(Group == "True positive"),
                 aes(y = ..density.., x = Value, fill = Group),
                 col = "black", binwidth = 0.1) +
  labs(x = "R Ratio", y = "Number of proteins") +
  theme_bw() + theme(legend.position = "right")