Home > front end >  How to put a black border around certain dots on a ggplot geom_point plot
How to put a black border around certain dots on a ggplot geom_point plot

Time:02-08

I am trying to make a geom plot using ggplot for some pathways of interest. I would like to put a black border around certain dots that are significant. -log10 > 1.2, so they are easier to identify. Is there anyway to do this in the package so I do not have to do in an illustrator package after I have produced the image? Thank you kindly for advice. [Image of current dot image][1]

[image of raw data ][2]

cols <- c("blue",
          "white",
          "red")

li <- c(-2, 2)

D1 <- ggplot(Practice, aes(Practice$case, Practice$pathway, 
      colour = Enrichment_score, size = Practice$ln))  
  geom_point(alpha = 0.8)   
  scale_colour_gradientn(colours = cols)  
  theme(legend.position="bottom")  
  scale_size(breaks = c(0, 1.2, 1.4), range =  c(0.06,12))  
  guides(size=guide_legend(title = "-log10(q value)"),
         scale_colour_gradient())  
  labs(colour = "Enrichment Score")  
  theme_bw()
  
D1   ggtitle("")  
  xlab("")   ylab("")   
  scale_x_discrete(limits=c("Responder vs Non-responder",
                            "Non-responder vs Control", 
                            "Responder vs Control", 
                            "Case vs Control")) ````````


  [1]: https://i.stack.imgur.com/aWzOf.png
  [2]: https://i.stack.imgur.com/Cblfb.png

CodePudding user response:

Since I do not have your original data, and you don't have an example graph, I'll use diamonds to see if this is want you want.

To "circle" the data point that you want to highlight, we can use an extra geom_point, and use some subset of data in it.

In your case, the subset can be like geom_point(data = subset(Practice, -log10(Enrichment_score) > 1.2), col = "black", stroke = 3, shape = 21).

library(tidyveres)

cols <- c("blue", "white", "red")
ggplot(diamonds, aes(cut, clarity, 
                    colour = price, size = depth))  
  geom_point(alpha = 0.8)   
  scale_colour_gradientn(colours = cols)  
  theme(legend.position="bottom")  
  scale_size(breaks = c(0, 1.2, 1.4), range =  c(0.06,12))  
  guides(size=guide_legend(title = "-log10(q value)"),
         scale_colour_gradient())  
  labs(colour = "Enrichment Score")  
  theme_bw()  
  geom_point(data = subset(diamonds, depth > 70), col = "black", stroke = 3, shape = 21)

geom_point_stroke_with_subset

Also, you don't need to use the dollar sign $ to specify column names in ggplot.

CodePudding user response:

Another way, which may be simpler, is to use shape 21 with geom_point:

library(ggplot2)

ggplot(mtcars, aes(factor(cyl), mpg))  
  geom_point(shape = 21,  stroke = 1, aes(colour = disp >= 250, fill = hp))  
  scale_colour_manual(values = c(`TRUE` = "black", `FALSE` = rgb(0,0,0,0)))


The manual colour scale makes the edge of shape 21 either black or transparent. Note the backticks for TRUE or FALSE.

  •  Tags:  
  • Related