0

I'm trying to represent a graph in R but when I paint it I get a ,1 next to high, low and normal, like this: (High,1) Is it possible to eliminate the apparentis and the ,1 so that only High, Low and Normal are shown?

Code:

output$grafica <-renderPlotly({
   p <- ggplot(data(), aes(x=as.factor(data()[,names(data())[15]]),
                           fill=as.factor(data()[,names(data())[5]])) + 
     geom_bar(stat="count") +
     scale_fill_manual(values=c("#810f7c", "#8856a7", "#8c96c6"))+
     theme(axis.text.x=element_text(angle=45, hjust=1))+
     scale_color_viridis(discrete = TRUE) + 
     labs(title="Number", 
          y="Issues", 
          x="Project",
          fill= "Priority")
 })

Thanks in advance.

enter image description here

  • This might solve your problem: https://stackoverflow.com/questions/49133395/strange-formatting-of-legend-in-ggplotly-in-r – motch Jan 28 '20 at 20:40

3 Answers3

0

add

scale_fill_manual(values=c("#810f7c", "#8856a7", "#8c96c6"),
labels=c("High", "Low", "Normal"))

to your scale_fill_manual()

Daniel_j_iii
  • 3,041
  • 2
  • 11
  • 27
0

i obtain the same with this code :

output$grafica4 <-renderPlotly({
   p <- ggplot(data(), aes(x=as.factor(data()[,names(data())[15]]),
                           fill=as.factor(data()[,names(data())[5]]))) + 
     geom_bar(stat="count") +
     scale_fill_manual(labels=c("High", "Low", "Normal"), 
                       values=c("#810f7c", "#8856a7","#8c96c6"),
                       name="Priority")+
     theme(axis.text.x=element_text(angle=45, hjust=1))+
     scale_color_viridis(discrete = TRUE) + 
     labs(title="Number", 
          y="Issues", 
          x="Project")
 })

enter image description here

0

New code :

 output$grafica4 <-renderPlotly({
   p <- ggplot(data(), aes(x=as.factor(data()[,names(data())[15]]),
                           fill=as.factor(data()[,names(data())[5]]))) + 
     geom_bar(stat="count") +
     #scale_fill_manual(labels=c("High", "Low", "Normal"), 
      #                 values=c("#810f7c", "#8856a7","#8c96c6"),
       #                name="Priority")+
     scale_shape_discrete(name ="Priority", breaks=c("High", "Low", "Normal"), 
                          labels=c("High", "Low", "Normal"))+
      theme(axis.text.x=element_text(angle=45, hjust=1))+
     scale_color_viridis(discrete = TRUE) + 
     labs(title="Number", 
          y="Issues", 
          x="Project",
          fill="Priority")
 })

enter image description here