R中的ggparied图(看不到所有成对的线) [英] ggparied plot in R (don't see all the paired lines)
问题描述
我有一个数据框,如下所示:
I have a dataframe as follows:
我想将ggpaired用于配对比较.我的R代码如下:
I want to apply ggpaired for paired comparison. My R code is as follows:
Data$State<-factor(Data$State, levels = c("PDSS", "MSDD","HCP"))
Data$Condition<-factor(Data$Condition, levels = c("SM", "DM"))
ggpaired(Data, x = "Condition", y = "Value",color = "Condition",line.color = "grey", line.size = 0.4, palette = "jco",facet.by = "State", short.panel.labs = FALSE)
我收到如下错误: geom_path:每个组仅包含一个观察值.您是否需要调整组的审美?
我的输出文件如下所示.
My output file looks like this.
我应该如何拥有所有配对的线?非常感谢您的帮助!
How should I have all the paired lines? Any help is highly appreciated!
谢谢,Vrutang
Thanks, Vrutang
推荐答案
您试图链接成对的数据点,并且需要一些标识才能为每对配对.您的数据集缺少标识变量.变量ID被添加到数据集中:
You were trying to link pairs of data points and it requires some identification to link by for each pair. Your data set is missing an identification variable. A variable ID is added into the data set:
> str(Data)
'data.frame': 44 obs. of 4 variables:
$ State : Factor w/ 3 levels "PDSS","MSDD",..: 3 3 3 3 3 3 3 2 2 2 ...
$ Condition: Factor w/ 2 levels "SM","DM": 1 1 1 1 1 1 1 1 1 1 ...
$ Value : num 0.91 1.24 1.02 1.29 1.38 1.51 1.18 0.88 1.18 0.96 ...
$ ID : int 1 2 3 4 5 6 7 8 9 10 ...
然后,您要做的就是在 ggpaired
语句中添加 id = option
,如下所示:
Then, all you need to do is to add an id = option
within the ggpaired
statement, as follows:
ggpaired(Data, x = "Condition", y = "Value",color = "Condition",
line.color = "grey", line.size = 0.4, palette = "jco", id = "ID",
facet.by = "State", short.panel.labs = FALSE)
结果:
这篇关于R中的ggparied图(看不到所有成对的线)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!