Question: ggplot2, point with border
2
gravatar for reubenmcgregor88
2.0 years ago by
reubenmcgregor8840 wrote:

Hi,

Hoping someone can help with what may seem like a simple question. I would like to use ggplot2 to plot a graph with a black border but a custom fill.

Using the following code I have managed to puoulate the graph as I would like it:

# creating color palette
>cols <- c("red" = "red", "orange" = "orange", "nonsignificant" = "darkgrey", "Increased" = "#00B2FF", "Decreased" = "#00B2FF")

# Make a basic ggplot2 object
>vol <- ggplot(data, aes(x = lfc, y = pval, color = color, labels=gene))

# inserting mnaual colors as per color pallette and more
>vol +   
  scale_colour_manual(values = cols) +
  ggtitle(label = "Volcano Plot", subtitle = "Colored by fold-change direction") +
  geom_point(size = 2.5, alpha = 1, na.rm = T) +
  theme_bw(base_size = 14) + 
  theme(legend.position = "right") + 
  xlab(expression(log[2]("VitD" / "Carrier"))) + 
  ylab(expression(-log[10]("FDR"))) +
  geom_hline(yintercept = 1, colour="#990000", linetype="dashed") + geom_vline(xintercept = 0.586, colour="#990000", linetype="dashed") + geom_vline(xintercept = -0.586, colour="#990000", linetype="dashed") +
  scale_y_continuous(trans = "log1p")

Gives me the plot:

enter image description here

I understand that I need to define points as shape 21 before defining both color and fill t get different colors for border and fill. So I tried adding ,shape = 21, colour = "black" into my geom_point() agreement, but this turns everything black

>  vol +   
  ggtitle(label = "Volcano Plot", subtitle = "Colored by fold-change direction") +
  geom_point(size = 2.5, alpha = 1, na.rm = T, shape = 21, colour = "black") +
  scale_colour_manual(values = cols) +
  theme_bw(base_size = 14) + 
  theme(legend.position = "right") + 
  xlab(expression(log[2]("VitD" / "Carrier"))) + 
  ylab(expression(-log[10]("FDR"))) + 
  geom_hline(yintercept = 1, colour="#990000", linetype="dashed") + geom_vline(xintercept = 0.586, colour="#990000", linetype="dashed") + geom_vline(xintercept = -0.586, colour="#990000", linetype="dashed") +
  scale_y_continuous(trans = "log1p")

enter image description here

THANKS!!

ggplot ggplot2 • 13k views
ADD COMMENTlink modified 2.0 years ago by e.rempel770 • written 2.0 years ago by reubenmcgregor8840

I added code markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

ADD REPLYlink written 2.0 years ago by WouterDeCoster40k

Ah, gotcha.

Thanks will remember this next time.

ADD REPLYlink written 2.0 years ago by reubenmcgregor8840
5
gravatar for e.rempel
2.0 years ago by
e.rempel770
Germany, Heidelberg, COS
e.rempel770 wrote:

Hi,

I assume (haven't tested it on your data), that you should merely replace color = color with fill = color in your assignment of vol

ADD COMMENTlink written 2.0 years ago by e.rempel770
1

Thanks so much,

This has made the following graph now, so colors and black surrounding working now:

enter image description here

Sorry to be a pain, any idea why my color palette has been overwritten somehow?

vol <- ggplot(data, aes(x = lfc, y = pval, fill = color, labels=gene))

vol + ggtitle(label = "Volcano Plot", subtitle = "Colored by fold-change direction") +
          scale_colour_manual(values = cols) +
          geom_point(size = 2.5, alpha = 1, na.rm = T, shape = 21, colour = "black") +
          theme_bw(base_size = 14) + # change overall theme
          theme(legend.position = "right") + # change the legend
          xlab(expression(log[2]("VitD" / "Carrier"))) + # Change X-Axis label
          ylab(expression(-log[10]("FDR"))) + # Change Y-Axis label
          geom_hline(yintercept = 1, colour="#990000", linetype="dashed") + geom_vline(xintercept = 0.586, colour="#990000", linetype="dashed") + geom_vline(xintercept = -0.586, colour="#990000", linetype="dashed") + # Add p-adj value cutoff line
          scale_y_continuous(trans = "log1p") # Scale yaxis due to large p-values
ADD REPLYlink modified 2.0 years ago • written 2.0 years ago by reubenmcgregor8840
1

You want to change scale_colour_manual to scale_fill_manual

ADD REPLYlink written 2.0 years ago by fanli.gcb670

This is strange. Is the named vector cols still in your environment?

ADD REPLYlink written 2.0 years ago by e.rempel770

It is indeed (between ** below), which is why I am very confused at the random colour selection?

vol +   
  ggtitle(label = "Volcano Plot", subtitle = "Colored by fold-change direction") +
  geom_point(size = 2.5, alpha = 1, na.rm = T, shape=21, color = "black") +
  **scale_colour_manual(values = cols) +**
  theme_bw(base_size = 14) + 
  theme(legend.position = "right") + 
  xlab(expression(log[2]("VitD" / "Carrier"))) + 
  ylab(expression(-log[10]("FDR"))) + 
  geom_hline(yintercept = 1, colour="#990000", linetype="dashed") + geom_vline(xintercept = 0.586, colour="#990000", linetype="dashed") + geom_vline(xintercept = -0.586, colour="#990000", linetype="dashed") +
  scale_y_continuous(trans = "log1p")

hmmm

ADD REPLYlink modified 2.0 years ago • written 2.0 years ago by reubenmcgregor8840

The only thing(s) I can suggest right now is to modify scale_colour_manual(name='color', values = cols) and to print cols out (just to check it is still there).

ADD REPLYlink written 2.0 years ago by e.rempel770
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 728 users visited in the last hour