0

I am looking for setting my own colors for on the below plot :

ggplot

with the following part of code :

# Save PDF - Chisquare
pdf(file="Moschopoulos_Distribution.pdf")
color_curve <- c("red", "blue", "green", "grey", "black")
as.data.frame(y3) %>%
  mutate(row = row_number()) %>%     # add row to simplify next step
  pivot_longer(-row) %>%             # reshape long
  mutate(name = recode(name, V1="z = 0.9595", V2="z = 1.087", V3="z = 1.2395", V4="z = 1.45", V5="z = 1.688")) %>%
  ggplot(aes(value, color = name)) + # map x to value, color to name
  geom_density() +
  xlab(TeX("Distribution")) +
  ylab("Number of occurences") +
  ggtitle(TeX("Distribution of Ratio $(b_{sp}/b_{ph})^2$ for each redshift")) +
  theme(plot.title = element_text(hjust = 0.5))
dev.off()

How could I set my own colors for each curve ?

I tried to do into code snippet above :

color_curve <- c("red", "blue", "green", "grey", "black")
ggplot(aes(value, color = color_curve)) +

but I get an error.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 3
    You could set your colors via `+ scale_color_manual(values = color_curve)`. – stefan Oct 07 '21 at 20:39
  • 1
    @stefan . Great, it works ! thanks –  Oct 07 '21 at 20:53
  • @stefan, please post as answer ... – Ben Bolker Oct 07 '21 at 20:59
  • @stefan . By the way, if I don't set my own colors, what are the names or hexacodes of the color of the curves in the plot of my post above ? –  Oct 07 '21 at 21:10
  • 1
    You could get the hex codes of e.g. the first 5 default colors via `scales::hue_pal()(5)` – stefan Oct 07 '21 at 21:12
  • @youpilat13: I have removed the answer that was merged into the question. By all means, do post an answer. Click on the blue "Answer Your Question" button at the bottom of the page. – halfer Oct 07 '21 at 21:30

0 Answers0