data9
data9

Reputation: 97

Change aesthetics in ggplot

I am new to graphs in R. I am trying to construct a forest plot to compare Odds ratio and CI. However the code I got from a stckoverflow post seems to be more aesthetic then I need. Below is the sample of data, code and image. I am trying to remove all colour aestheticsand just need white background, black lines and different black shapes for odds points. and also can i put the unadjusted anaemia first rather than the default one that is in the given image.

Data

lag pollute or  lcl ucl
Other Backward Caste    Unadjusted anaemia  1.32    0.9 1.93
Other Backward Caste    Adjusted anaemia    1.25    0.84    1.87
Schedule Caste  Unadjusted anaemia  1.66    1.09    2.51
Schedule Caste  Adjusted anaemia    1.4 0.9 2.19
Schedule Tribe  Unadjusted anaemia  2.3 1.34    3.93
Schedule Tribe  Adjusted anaemia    1.93    1.08    3.44
General Unadjusted anaemia  1   1   1
General Adjusted anaemia    1   1   1

R Code

ggplot(dat, aes(x = pollute, y = or, ymin = lcl, ymax = ucl)) + geom_pointrange(aes(color=factor(lag)), position=position_dodge(width=0.3)) + 
  ylab("Odds ratio & 95% CI") + geom_hline(aes(yintercept = 1)) + scale_color_discrete(name = "") + xlab("")

Output image

Thanks in Advance!!

Upvotes: 0

Views: 720

Answers (1)

Jibin
Jibin

Reputation: 333

Try this,

library(ggplot2)
ggplot(dat, aes(x = pollute, y = or, ymin = lcl, ymax = ucl)) + 
  geom_pointrange(aes(shape = lag), position=position_dodge(width=0.3)) +  
  ylab("Odds ratio & 95% CI") + 
  geom_hline(aes(yintercept = 1)) +
  scale_color_discrete(name = "") +  xlab("") +
  theme(panel.background = element_rect(fill = 'white'))

Upvotes: 2

Related Questions