Legend values combined geom_point and geom_hline

I am trying to customise the legends in my Shiny App, and am very close but when I use scale_colour_manual and scale_linetype_manual together the legends values end up in the format (legend value, 1), as per the screenshot below. You can also see the app here https://beniam.shinyapps.io/Alpine/

I am not sure why this happens or how to change them, when I have tried adding 'labels' or 'breaks' into the code it doesn't do anything.

My code is

#main chart    
    plot <- ggplot(data = alpine %>% filter(Year == input$yearvalue & Location == input$var5), aes(x = Date, y = Depth, colour = Type)) + 
    geom_point() +
    ylim(0, 200) +
    theme_minimal(base_size = 10) + 
    geom_smooth(color = 'Dodgerblue', method = 'gam', se = FALSE) +
    scale_colour_manual(name = "Type of Snow", values=c("#99d8ff", "#2e4d82")) +
    
     
    geom_hline(aes(yintercept= 100, linetype = "Current Year Mean"), colour= 'green') +
    geom_hline(aes(yintercept= 80, linetype = "2010 Mean"), colour= 'black') +
    scale_linetype_manual(name ="", values = c('dotted','dotted')) 

I can't reproduce your issue....


library(tidyverse)
set.seed(42)
ex_df <- data.frame(
  Date=seq.Date(from=as.Date('2019-01-01'),by="day",length.out = 365),
  Depth =30+cumsum(sample(c(-10,10), size=365, replace=TRUE)),
  Type = factor(sample(c("Natural","Artificial"), size=365, replace=TRUE))
)


plot <- ggplot(data =ex_df, aes(x = Date, y = Depth, colour = Type)) + 
  geom_point() +
  ylim(0, 200) +
  theme_minimal(base_size = 10) + 
  geom_smooth(color = 'Dodgerblue', method = 'gam', se = FALSE) +
  scale_colour_manual(name = "Type of Snow", values=c("#99d8ff", "#2e4d82")) +
  geom_hline(aes(yintercept= 100, linetype = "Current Year Mean"), colour= 'green') +
  geom_hline(aes(yintercept= 80, linetype = "2010 Mean"), colour= 'black') +
  scale_linetype_manual(name ="", values = c('dotted','dotted')) 

plot

Thanks for this, I will do some further investigation to try and figure out what is causing the issue.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.