Home > database >  ggplot2 center the highlighted sample
ggplot2 center the highlighted sample

Time:10-26

I have a dataframe like this:

A   WNT 0.2298387   tumor
B   WNT 1.310402    tumor
C   WNT -1.0689713  tumor
D   WNT -1.8234757  tumor
E   WNT -2.4223726  tumor
F   WNT 0.2772998   tumor
G   Androgen    1.6836632   normal
H   Androgen    0.1874877   normal
I   Androgen    2.6503196   normal
J   Androgen    -0.8392165  normal
K   Androgen    1.3389321   normal
L   Androgen    -1.0377083  normal
A   PQR 0.686791895 tumor
B   PQR 0.941747447 tumor
C   PQR 0.168153523 tumor
D   PQR 0.647530738 tumor
E   PQR 0.970685676 tumor
F   PQR 0.201253352 tumor
G   XYZ 0.920460621 normal
H   XYZ 0.340050347 normal
I   XYZ 0.210318777 normal
J   XYZ 0.395990146 normal
K   XYZ 0.993182658 normal
L   XYZ 0.267444063 normal

I would like to use ggplot to highlight a specific sample, lets say G with a triangle. I tried this:

ggplot(df, aes(x=Pathway, y=Activity, fill=TissueType))   
  geom_boxplot(outlier.shape = NA)   scale_fill_manual(values = c("#7CCD7C" ,"#D8BFD8"))   
  geom_point(data = df[which(df$SampleName %like% "G"),], aes(Pathway, Activity, fill = TissueType), fill = '#d51030', color = '#d53010', size=3, shape = 24)   
  theme_bw() 

However, I am unable to get the specific dot in the center (it gets out of the boxplot) as seen here:

enter image description here

how can I get the red triangles to the center?

CodePudding user response:

Kindly let me know if this what you were anticipating.

ggplot(data, aes(x=Pathway, y=Activity))  
  geom_boxplot(aes(fill=TissueType))   scale_fill_manual(values = c("#7CCD7C" ,"#D8BFD8"))  
  geom_point(data = data[which(data$SampleName %like% "G"),],position=position_dodge(width=0.75),aes(group=TissueType), fill = '#d51030', color = '#d53010', size=3, shape = 24)

enter image description here

  • Related