0

I'm doing a R plot and to each set of data I want it to be shown in a different color. To do that I'm using scale_color_manual(). The thing works perfectly fine with the first nine or ten curves, but in the last two ones, ggplot do not set the color I had chose.

I'll put the code down here and a copy of the plot I'm getting so you can see what I'm talking about. As it is a lot of different set of data, I will not post it here, but the problem is at the last two curve called here as "Saída R11" and "Saída R12".

ggplot() +
  geom_point(data = C1D1, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R1"), size = a) + 
  geom_point(data = C1D2, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R2"), size = a) + 
  geom_point(data = C1D3, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R3"), size = a) + 
  geom_point(data = C1D4, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R4"), size = a) + 
  geom_point(data = C1D5, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R5"), size = a) + 
  geom_point(data = C1D6, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R6"), size = a) + 
  geom_point(data = C1D7, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R7"), size = a) + 
  geom_point(data = C1D8, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R8"), size = a) + 
  geom_point(data = C1D9, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R9"), size = a) + 
  geom_point(data = C1D10, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R10"), size = a) + 
  geom_point(data = C1D11, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R11"), size = a) +
  geom_point(data = C1D12, mapping = aes(x <- V2, y = V1V2/R, colour = "Saída R12"), size = a) +
   annotate("rect", fill = "#D1C5CF", alpha = 0.4, xmin = -0.05, xmax = xcomp, ymin =  yMIN, ymax = yMAX) + 
  annotate("rect", fill = "#B3C5DD", alpha = 0.16, xmin = xcomp, xmax = 3.9, ymin =  yMIN, ymax = yMAX) + 
  annotate(geom="text", x=0.16, y=0.038, label="Região", color="#FF85D4") +
  annotate(geom="text", x=0.135, y=0.036, label="Saturada", color="#FF85D4") +
  annotate(geom="text", x=3.78, y=0.038, label="Região", color="#6B7AFF") +
  annotate(geom="text", x=3.81, y=0.036, label="Ativa", color="#6B7AFF") +
  geom_line(data = ivCurve, mapping <- aes(x <- x1, y<-y1)) +



scale_colour_manual(TeX('$Corrente\\, I_{B}\\, (?A)$'), 
                     breaks = c("Saída R1","Saída R2","Saída R3","Saída R4","Saída R5","Saída R6","Saída R7","Saída R8","Saída R9","Saída R10", "Saída R11", "Saída R12"),
                     values = c("#000000","#B1DF1C","#88FB0C","#41F710","#09F668","#03F8C7","#0AB8F8","#900BF6","#CF0FE8","#EE13C6", "purple","red")) +

Here is a link to an image of the plot

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
kplt
  • 59
  • 6
  • 6
    I think life will be much easier if you can get your data into one data frame. Generally with `ggplot2` if you find you are adding the same geom over and over, you're doing it wrong. – neilfws May 02 '19 at 03:00
  • 5
    Use `=` to set variables inside functions, not `<-` – camille May 02 '19 at 03:07
  • 3
    have you tried `rbind`ing your C1D1 : C1D12 data frames into one, and doing only one `geom_point` call? – PavoDive May 02 '19 at 03:27
  • 2
    @llgsi: Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung May 02 '19 at 04:01

0 Answers0