Home > Software engineering >  When I try to add "scale_shape_manual", it shows up error "All unnamed arguments must
When I try to add "scale_shape_manual", it shows up error "All unnamed arguments must

Time:11-14

I'm trying to plot line chart, but when I try to add "scale_shape_manual", it shows up error "All unnamed arguments must be length 1".

Here is my original data:

Tiguan<-structure(list(GDD = c(487.95, 487.95, 487.95, 487.95, 487.95, 
487.95, 487.95, 487.95, 698.5, 698.5, 698.5, 698.5, 698.5, 698.5, 
698.5, 698.5, 900.25, 900.25, 900.25, 900.25, 900.25, 900.25, 
900.25, 900.25), Variété = c("Tiguan", "Tiguan", "Tiguan", 
"Tiguan", "Tiguan", "Tiguan", "Tiguan", "Tiguan", "Tiguan", "Tiguan", 
"Tiguan", "Tiguan", "Tiguan", "Tiguan", "Tiguan", "Tiguan", "Tiguan", 
"Tiguan", "Tiguan", "Tiguan", "Tiguan", "Tiguan", "Tiguan", "Tiguan"
), Treatment = c("IRR- & N-  113", "IRR- & N   123", "IRR  & N-  139", 
"IRR  & N   147", "IRR- & N-  211", "IRR- & N   223", "IRR  & N-  237", 
"IRR  & N   247", "IRR- & N-  113", "IRR- & N   123", "IRR  & N-  139", 
"IRR  & N   147", "IRR- & N-  211", "IRR- & N   223", "IRR  & N-  237", 
"IRR  & N   247", "IRR- & N-  113", "IRR- & N   123", "IRR  & N-  139", 
"IRR  & N   147", "IRR- & N-  211", "IRR- & N   223", "IRR  & N-  237", 
"IRR  & N   247"), Indice_foliaire_LAI = c(0.620739348837209, 
0.644567476923077, 0.88557975, 0.588256271186441, 0.835278337078652, 
0.854556, 1.53936294573643, 1.34369638554217, 1.10213335714286, 
0.943865953947369, 2.00982867850099, 1.20625386996904, 2.33443615062762, 
2.26587034439834, 2.58574120065789, 2.33340772118959, 1.7192244043956, 
1.33842068847352, 2.40247312056738, 2.07099759264126, 2.07436100271739, 
2.43362987573965, 2.81841503695882, 2.43609819310345)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -24L))

Here is the code I use:

library(ggplot2)
library(readxl)
library(scales)
library(tidyverse)

ggplot(Tiguan,aes(GDD,Indice_foliaire_LAI,color=Treatment,shape=Treatment)) 
  geom_point(cex=2.5) 
  geom_smooth(aes(group = Treatment)) 
  scale_color_manual(values = c("#BC3C29FF","#BC3C29FF","#BC3C29FF", "#0072B5FF","#0072B5FF","#0072B5FF", "#E18727FF",  "#E18727FF",  "#E18727FF", "#20584EFF","#20584EFF","#20584EFF")) 
  scale_shape_manual(values = c("15","17","19", "15","17","19", "15","17","19", "15","17","19")) 
  labs(title="Tiguan MG-(0)000", x = "Degree Growing Days (°C)", y ="LAI") 
  theme_bw() 
  guides(color=guide_legend("Treatment",override.aes=list(fill=NA)),linetype=guide_legend("Treatment")) 
  theme(plot.title = element_text(hjust = 0, face="bold", size = 17,
                                  color = "Black"),
        panel.grid = element_line(color = "#B3B3B3",
                                  size = 0.75,
                                  linetype = 3),
        axis.text.x = element_text(angle = 90, hjust = 1),legend.position = "right")

Then it shows up:

Error: All unnamed arguments must be length 1

When I delete scale_shape_manual(values = c("15","17","19", "15","17","19", "15","17","19", "15","17","19")) I got the figure: enter image description here

But you can see that there's two treatments missing shapes in the legend. Any suggestions are welcome! Thanks!

CodePudding user response:

remove quotes from your values, i.e. use scale_shape_manual(values = c(15,17,19,15,17,19,15,17,19,15,17,19))

  • Related