此代码在R中生成曲线。如何更改此曲线的颜色?

时间:2018-05-21 15:36:29

标签: r ggplot2

此代码使用pwr和ggplot2包在R中生成曲线。如何更改此曲线的颜色?

library(pwr)
library(ggplot2)
P0 = c(0.05,0.06,0.11,0.104,0.16,0.106,0.01,0.1,
0.1,0.1,0.08,0.02)
P1 = c(0.1,0.05,0.12,0.101,0.12,0.105,0.024,0.04,
0.01,0.11,0.04,0.06)
effect.size = ES.w1(P0, P1)  
degrees = length(P0) - 1
pwr.chisq.test(
           w=effect.size, 
           N=NULL,           
           df=degrees, 
           power=0.80,       
           sig.level=0.05)
P.out <- pwr.chisq.test(
            w=effect.size, 
            N=NULL,            
            df=degrees, 
            power=0.80,        
           sig.level=0.05)
plot(P.out)
p <- plot(P.out)
p + theme_classic(base_size = 14)

2 个答案:

答案 0 :(得分:3)

红色似乎在pwr::plot.power.htest函数中被硬编码。但是,您可以编辑以某种黑客方式返回的ggplot对象来完成工作

p <- plot(P.out)
p$layers[[1]]$aes_params$colour <- "blue"

答案 1 :(得分:3)

以这种方式添加颜色信息:

plot(P.out)+ 
  geom_line(colour="blue")

enter image description here

使用相同的命令,您还可以使用HTML颜色代码,如下所示:

  geom_line(colour="#2E64FE")