Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This code generates a curve in R. How can I change the color of this curve?

Tags:

r

ggplot2

This code generates a curve in R using pwr and ggplot2 packages. How can I change the color of this curve?

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)
like image 895
Reza Avatar asked Nov 20 '25 15:11

Reza


2 Answers

Add color info in this way:

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

enter image description here

With the same command you can also use HTML color code, like this:

  geom_line(colour="#2E64FE")
like image 137
Terru_theTerror Avatar answered Nov 22 '25 04:11

Terru_theTerror


The color red seems to be hard coded in the pwr::plot.power.htest function. However you can edit the ggplot object that's returned in somewhat of a hacky way to get the job done

p <- plot(P.out)
p$layers[[1]]$aes_params$colour <- "blue"
like image 40
MrFlick Avatar answered Nov 22 '25 04:11

MrFlick