Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.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
在line.color是加权函数的情况下制作成对绘图?_R_Ggplot2_Colorbar_Ggpubr_Ggpairs - Fatal编程技术网

在line.color是加权函数的情况下制作成对绘图?

在line.color是加权函数的情况下制作成对绘图?,r,ggplot2,colorbar,ggpubr,ggpairs,R,Ggplot2,Colorbar,Ggpubr,Ggpairs,我有一些治疗前后的数据,想看看配对数据,所以我转向ggpaired。我能够让它与我的数据一起正常工作。(我模拟了一些与我正在使用的数据相似的数据,以便其他人可以随意处理。) 这将生成图像: 这很好,但我有很多值,比如说,前处理值为2,后处理值为1,你不能用线的颜色真实地想象它。在谷歌搜索时,我发现,我想这不是我所需要的。我不知道用什么方式来表达这个问题,并不断地寻找网络边缘线宽的结果 基本上,我想做的是:如果我有11个从3到2的观察值,我希望从3到2的线比,比如说,从1到0的线更暗,它只有3个

我有一些治疗前后的数据,想看看配对数据,所以我转向
ggpaired
。我能够让它与我的数据一起正常工作。(我模拟了一些与我正在使用的数据相似的数据,以便其他人可以随意处理。)

这将生成图像:

这很好,但我有很多值,比如说,前处理值为2,后处理值为1,你不能用线的颜色真实地想象它。在谷歌搜索时,我发现,我想这不是我所需要的。我不知道用什么方式来表达这个问题,并不断地寻找网络边缘线宽的结果

基本上,我想做的是:如果我有11个从3到2的观察值,我希望从3到2的线比,比如说,从1到0的线更暗,它只有3个观察值,有点像我在绘画中做的这个非常快速的模型:


我希望可以使用
line.color
(或者使用
line.weight
?)实现类似的功能,并通过权重(或者更具体地说,计数的数量)为线条着色,但我不是R的最佳选择(而且对它来说是新手),因此,如果有任何帮助,我将不胜感激,因为我不知道如何开始做类似的事情,我在谷歌上搜索的关于这个主题的一切似乎都与网络图有关。

你想要什么当然是可能的,但使用
ggpaired
可能不是最直接的方法(免责声明:我不太使用ggpubr包。)

ggplot2
基本上是一个包裹在底层
ggplot2
包函数周围的包。如果您想更改操作方式,那么在底层函数中进行更改是一种干净的方法。(如果你打算在将来使用R,那么深入学习黄铜大头钉也是一个很好的学习方法。)

下面是我如何做的,从原始数据帧开始
df.t

library(dplyr)

df.t %>%
  mutate(pair.order = rep(seq(1, n()/2), times = 2)) %>% # add new column to keep track of pairs
  tidyr::pivot_longer(cols = A:P, names_to = "facet") %>% # convert data to long form so all 
                                                          # values are captured in one variable
  ggplot(aes(x = V, y = value, fill = V)) +
  geom_boxplot() +  
  geom_line(data = . %>%                             # further data manipulation for line layer
              tidyr::pivot_wider(names_from = V) %>% # arrange values in pairs
              count(facet, D, F) %>%                 # & aggregate them for each treatment
              mutate(n = cut(n, breaks = c(0, 5, 10, Inf),
                             labels = c("n \u2264 5", "6 < n \u2264 10", "n > 10"))) %>%
              mutate(line.group = seq(1, n())) %>%   # add grouping identifier for line
              tidyr::pivot_longer(cols = D:F, names_to = "V"),  # return to long form
            aes(group = line.group, 
                colour = forcats::fct_rev(n)), # reverse category order for count
            size = 2) +                        # increase line size for easier comparison
  
  facet_wrap(~facet,     # split into 4 plot facets, one for each treatment
             labeller = labeller(facet = function(x) paste("Paired boxplot of", x, "ratings"))) +
  scale_x_discrete(labels = c("draft", "final")) +
  labs(y = "rating", colour = "Number of\ncounts") +
  ggsci::scale_fill_jco(guide = FALSE) + # not showing legend since it's the same as x-axis
  scale_colour_grey() +
  theme_pubr() +
  theme(legend.position = "right",
        axis.title.x = element_blank())
库(dplyr)
df.t%>%
mutate(pair.order=rep(seq(1,n()/2),times=2))%>%#添加新列以跟踪对
tidyr::pivot_longer(cols=A:P,names_to=“facet”)%>%#将数据转换为长格式,以便所有
#值被捕获到一个变量中
ggplot(aes(x=V,y=value,fill=V))+
geom_箱线图()+
geom_线(数据=.%>%#线层的进一步数据操作
tidyr::pivot_更宽(name_from=V)%>%#成对排列值
计数(刻面、D、F)%>%#并为每种处理将其聚合
突变(n=cut(n,breaks=c(0,5,10,Inf),
标签=c(“n\u2264 5”、“610”))%%>
mutate(line.group=seq(1,n())%>%#为行添加分组标识符
tidyr::pivot_longer(cols=D:F,name_to=“V”),#返回到long形式
aes(组=line.group,
颜色=猫::fct#U版本(n)),与计数的类别顺序相反
大小=2)+增加行大小以便于比较
面_包裹(~facet,#分为4个绘图面,每个处理一个
贴标机=贴标机(刻面=功能(x)粘贴(“x、评级的成对箱线图”))+
比例x离散(标签=c(“草稿”、“最终”))+
实验室(y=“评级”,color=“数量”)+
ggsci::scale_fill_jco(guide=FALSE)+#不显示图例,因为它与x轴相同
比例\颜色\灰色()+
主题_pubr()+
主题(legend.position=“right”,
axis.title.x=元素_blank())

您想要什么当然是可能的,但是使用
ggpaired
可能不是最简单的方法(免责声明:我不太使用ggpubr包。)

ggplot2
基本上是一个包裹在底层
ggplot2
包函数周围的包。如果您想更改操作方式,那么在底层函数中进行更改是一种干净的方法。(如果你打算在将来使用R,那么深入学习黄铜大头钉也是一个很好的学习方法。)

下面是我如何做的,从原始数据帧开始
df.t

library(dplyr)

df.t %>%
  mutate(pair.order = rep(seq(1, n()/2), times = 2)) %>% # add new column to keep track of pairs
  tidyr::pivot_longer(cols = A:P, names_to = "facet") %>% # convert data to long form so all 
                                                          # values are captured in one variable
  ggplot(aes(x = V, y = value, fill = V)) +
  geom_boxplot() +  
  geom_line(data = . %>%                             # further data manipulation for line layer
              tidyr::pivot_wider(names_from = V) %>% # arrange values in pairs
              count(facet, D, F) %>%                 # & aggregate them for each treatment
              mutate(n = cut(n, breaks = c(0, 5, 10, Inf),
                             labels = c("n \u2264 5", "6 < n \u2264 10", "n > 10"))) %>%
              mutate(line.group = seq(1, n())) %>%   # add grouping identifier for line
              tidyr::pivot_longer(cols = D:F, names_to = "V"),  # return to long form
            aes(group = line.group, 
                colour = forcats::fct_rev(n)), # reverse category order for count
            size = 2) +                        # increase line size for easier comparison
  
  facet_wrap(~facet,     # split into 4 plot facets, one for each treatment
             labeller = labeller(facet = function(x) paste("Paired boxplot of", x, "ratings"))) +
  scale_x_discrete(labels = c("draft", "final")) +
  labs(y = "rating", colour = "Number of\ncounts") +
  ggsci::scale_fill_jco(guide = FALSE) + # not showing legend since it's the same as x-axis
  scale_colour_grey() +
  theme_pubr() +
  theme(legend.position = "right",
        axis.title.x = element_blank())
库(dplyr)
df.t%>%
mutate(pair.order=rep(seq(1,n()/2),times=2))%>%#添加新列以跟踪对
tidyr::pivot_longer(cols=A:P,names_to=“facet”)%>%#将数据转换为长格式,以便所有
#值被捕获到一个变量中
ggplot(aes(x=V,y=value,fill=V))+
geom_箱线图()+
geom_线(数据=.%>%#线层的进一步数据操作
tidyr::pivot_更宽(name_from=V)%>%#成对排列值
计数(刻面、D、F)%>%#并为每种处理将其聚合
突变(n=cut(n,breaks=c(0,5,10,Inf),
标签=c(“n\u2264 5”、“610”))%%>
mutate(line.group=seq(1,n())%>%#为行添加分组标识符
tidyr::pivot_longer(cols=D:F,name_to=“V”),#返回到long形式
aes(组=line.group,
颜色=猫::fct#U版本(n)),与计数的类别顺序相反
大小=2)+增加行大小以便于比较
面_包裹(~facet,#分为4个绘图面,每个处理一个
贴标机=贴标机(刻面=功能(x)粘贴(“x、评级的成对箱线图”))+
比例x离散(标签=c(“草稿”、“最终”))+
实验室(y=“评级”,color=“数量”)+
ggsci::scale_fill_jco(guide=FALSE)+#不显示图例,因为它与x轴相同
比例\颜色\灰色(
library(dplyr)

df.t %>%
  mutate(pair.order = rep(seq(1, n()/2), times = 2)) %>% # add new column to keep track of pairs
  tidyr::pivot_longer(cols = A:P, names_to = "facet") %>% # convert data to long form so all 
                                                          # values are captured in one variable
  ggplot(aes(x = V, y = value, fill = V)) +
  geom_boxplot() +  
  geom_line(data = . %>%                             # further data manipulation for line layer
              tidyr::pivot_wider(names_from = V) %>% # arrange values in pairs
              count(facet, D, F) %>%                 # & aggregate them for each treatment
              mutate(n = cut(n, breaks = c(0, 5, 10, Inf),
                             labels = c("n \u2264 5", "6 < n \u2264 10", "n > 10"))) %>%
              mutate(line.group = seq(1, n())) %>%   # add grouping identifier for line
              tidyr::pivot_longer(cols = D:F, names_to = "V"),  # return to long form
            aes(group = line.group, 
                colour = forcats::fct_rev(n)), # reverse category order for count
            size = 2) +                        # increase line size for easier comparison
  
  facet_wrap(~facet,     # split into 4 plot facets, one for each treatment
             labeller = labeller(facet = function(x) paste("Paired boxplot of", x, "ratings"))) +
  scale_x_discrete(labels = c("draft", "final")) +
  labs(y = "rating", colour = "Number of\ncounts") +
  ggsci::scale_fill_jco(guide = FALSE) + # not showing legend since it's the same as x-axis
  scale_colour_grey() +
  theme_pubr() +
  theme(legend.position = "right",
        axis.title.x = element_blank())