0

I've added guides(fill = guide_legend) but the legend doesn't show out Beside, I would like to add it at the top right so what should I do?

my code:

Month <- month.abb
Value <- c(20821,28062,20481,22013,22045,19586,23377,27317,20488,23492,20629,23990)
Percentage <- c(0.5314,0.7018,0.5878,0.6463,0.6493,0.6150,0.6530,0.7214,0.6208,0.6421,0.6467,0.6522)
df <- data.frame(Month,Value,Percentage)
df$Month <- factor(df$Month, levels = Month)

library(ggplot2)
library(scales)

p3 <- ggplot(df,aes(x = Month))+ geom_line(aes(y=Value,group=1),color ="#68382C" ,size =1.5)
p3 <- p3 + geom_line(aes(y=Percentage*39000,group=1),color = "#00A4E6",size =1.5)
p3 <- p3 + scale_y_continuous(sec.axis = sec_axis(~./35000,name = "Percentage",labels = scales::percent_format()))
p3 <- p3 + labs(x=NULL)
p3 <- p3 + guides(fill = guide_legend)

enter image description here

Let's Yo
  • 335
  • 1
  • 3
  • 11
  • 3
    Have you seen [this question](https://stackoverflow.com/questions/10747307/legend-placement-ggplot-relative-to-plotting-region)? – jazzurro Jan 15 '18 at 02:41
  • 1
    The suggested duplicate is correct when it comes to legend placement, but to have the legend show up you'll need to either reshape your data, or place the `color` inside `aes`. – Axeman Jan 15 '18 at 10:20

0 Answers0