点图不同的指标,取决于值,在R中

时间:2015-10-04 13:43:00

标签: r graphics lattice

我正在想象比值比。

您可以在

下找到虚假数据和图表
Data <- data.frame(
odds = sample(0:9),
pvalue = c(0.1,0.04,0.02,0.03,0.2,0.5,0.03,
0.12,0.12,0.014),
Y = sample(c("a", "b"), 5, replace = TRUE),
letters = letters[1:10]
)
library(lattice)
dotplot(letters ~  odds| Y, data =Data,
aspect=0.5, layout = c(1,2), ylab=NULL)

我想显示p值大于0.05的实心圆圈,如果值小于0.05则显示空心圆圈。

3 个答案:

答案 0 :(得分:1)

我们可以根据'pvalue'列为空/实心圆圈指定值为1/20的pch

dotplot(letters ~ odds| Y, data=Data, aspect= 0.5, layout= c(1,2), 
          ylab=NULL, pch= ifelse(Data$pvalue > 0.05, 20, 1))

答案 1 :(得分:1)

group参数和pch也应该完成这项工作:

dotplot(letters ~  odds| Y, data =Data,
        aspect=0.5, layout = c(1,2), ylab=NULL, 
        groups = pvalue <= 0.05,
        pch = c(19, 21))

答案 2 :(得分:0)

使用ggplot2

很容易创建
library(ggplot2)
Data$significant <- Data$pvalue > 0.05
ggplot(Data, aes(x=odds, y=letters, shape=significant)) +
         geom_point(size=4) +
  scale_x_continuous(breaks = seq(from=0, to= 8, by=2)) +
  scale_shape_manual(values=c(1, 16)) +
  ylab("") +
  facet_wrap(~ Y, ncol = 1, nrow = 2) +
  theme_bw()

GGPlot version