Reputation: 501
I have made a plot displaying multiple facets of my data. The colour bar created by scale_colour_gradientn
is confusing because it shows percentage breakdowns. Could I get rid of these percentage breakdowns and add my own. I have tried using values
and breaks
parameters but with no luck. I think maybe ggplot
is confused because most of the values are either very small or close to 1. I have added a toy dataset, code and image output below.
dput(df)
structure(list(Mean.Count = c(30404.8407153174, 15689.4221807262,
30404.8407153174, 15689.4221807262),
Log2FC = c(-0.00357013689574257, -0.00417251481039714, 0.306809506669248, 0.224653107007472),
Adj.P.Value = c(0.988865360408676, 0.981816989495127, 0.00202882891738576, 2.72576774009609e-05),
TimeKD = c("A", "A", "B", "B"),
Gene = c("HSPA5", "MYH9", "HSPA5", "MYH9")),
row.names = c("HSPA5", "MYH9", "HSPA51", "MYH91"),
class = "data.frame")
plotting code
ggplot(df, aes(x = Gene, y = Log2FC, group=TimeKD)) +
geom_point(aes(color = -Adj.P.Value, size = Mean.Count, shape = TimeKD), alpha = 0.5)+
coord_flip() +
scale_colour_gradientn(
colours = grDevices::colorRampPalette(c("black", "cyan", "violet"))(n = 200),
values = c(0.0, 1.0),
#breaks = c(0.0, 0.0001, 0.001, 0.1, 1.0), <- removes legend for some reason
space = "Lab",
na.value = "grey50",
guide = "colourbar",
aesthetics = "colour"
)+
scale_x_discrete(limits = rev)
output (without the breaks
parameter)
Upvotes: 0
Views: 103
Reputation: 603
Because your Adj.P.value
is numeric, you have to break it into categories first.
library(dplyr)
library(ggplot2)
df<- df %>%
mutate(Adj.P.Value = cut(Adj.P.Value, breaks = c(0, 0.01, 0.05, 100), labels = c("<0.01", "<0.05", ">0.05")))
ggplot(df, aes(x = Gene, y = Log2FC, group=TimeKD)) +
geom_point(aes(color = Adj.P.Value, size = Mean.Count, shape = TimeKD), alpha = 0.5)+
coord_flip()
Upvotes: 1