Home > Enterprise >  Change colour of a specific diamond on a forest plot using ggplot2
Change colour of a specific diamond on a forest plot using ggplot2

Time:11-19

I am trying to highlight one specific diamond of a variable on my forest plot using ggplot but I cannot find how to include this. I am trying to change the colour of "Periodontitis (Yes)".

dataset_unstratified$variables <- factor(dataset_unstratified$variables
                                         , levels = c("Intercept (Skeletal Muscle Mass Index)","Periodontitis (Yes)", "Sex(Men)", "Age", "Body-Mass Index", "Smoker", "Former Smoker",
                                                      "Diabetes","Prediabetes","Education (Low)","Education (Medium)","Daily energy intake",
                                                      "Daily protein intake", "Vitamin D2 and D3", "Bone Mineral Density"))
dataset_unstratified <- dataset_unstratified[order(dataset_unstratified$variables), ]

plot_width <- 100
wrapper <- function(x)  {   
  paste(strwrap(x, width = plot_width), collapse = "\n") 
}

plot1 <- ggplot(dataset_unstratified, aes(y=variables, x=coefficients))  
  geom_point(shape = 18, size = 5)    
  theme(axis.title.y = element_blank())  
  xlab("Beta-coefficients with 95% Confidence Intervals")    
  ylab("Model variables")   theme(axis.title.y = element_blank())  
  labs(title = wrapper("a) SMMI and periodontitis"))  
  geom_errorbarh(aes(xmin = `2.5 %`, xmax = `97.5 %`), height = 0.25)  
  geom_vline(xintercept = 0, color = "blue", linetype = "dashed", cex = 1, alpha = 0.5)

CodePudding user response:

Your code is currently not enter image description here

  • Related