ggplot(data=plotdata, mapping=aes(x='years')) + geom\line(aes(y='USA'), color = 'blue')…
Jump to turn (13)
- 1ggplot(data=plotdata, mapping=aes(x='years')) + geom\line(aes(y='USA'), color =
- 2i get SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
- 3for guides i get NameError: name 'c' is not defined
- 4i get PlotnineError: "guide\legend does not undestand attribute 'labels'" for gu
- 5i get UndefinedVariableError: name 'Country' is not defined
- 6no country is not a column in my df. I got it from your previously given code
- 7i don't get a legend. it's the same graph but with ggplot: (8778267283399) as th
- 8the error is AttributeError: 'ggplot' object has no attribute 'show'
- 9the same graph comes with no legend
- 10i get PlotnineError: "Aesthetics {'color'} specified two times."
- 11i get PlotnineError: "Could not evaluate the 'color' mapping: 'Country' (origina
- 12SyntaxError: invalid syntax
- 13ggplot(data=plotdata) + geom\line(aes(x='years', y='USA'), color='blue') + geom\
- User
ggplot(data=plotdata, mapping=aes(x='years')) + geom_line(aes(y='USA'), color = 'blue') + geom_line(aes(y='JPN'), color = 'red') + geom_line(aes(y='AUS'), color = 'green')
this is my python code. how do I add a legend?
- Assistant
You can add a legend to your plot by using the
scale_color_manual()function and specifying the labels for each line.Here is an example of how you can add a legend to your plot:
lessggplot(data=plotdata, mapping=aes(x='years')) + geom_line(aes(y='USA'), color = 'blue') + geom_line(aes(y='JPN'), color = 'red') + geom_line(aes(y='AUS'), color = 'green') + scale_color_manual(name = "Country", values = c("blue"="USA", "red"="JPN", "green"="AUS"))