ggplot2 label out of the graph in likert scale

前端 未结 3 1705

I have a ggplot made of a likert-scale using the package likert by jason.bryer (see). If you run the code with the original data here, then my extrem label (in the far right) i

相关标签:
3条回答
  • 2021-02-11 05:58

    So first of all, while the far right elements of the legend do not display, they do render properly in the pdf.

    The problem is that the legend is just too long, so it gets clipped. One option of course is to just make the display window larger. Another is to make the legend smaller. You can do that by adding one line to the end of the definition of p:

    p <- plot(competence_bachelor_plot, centered = FALSE, include.histogram = FALSE) + 
      ggtitle("How do you rate your skills gained with the Bachelor's?*") + 
      theme(axis.text.y = element_text(colour = "black"), axis.text.x = element_text(colour = "black"))+
      theme(legend.key.size=unit(.01,"npc"))
    

    You can also remove the name ("Response"), since it's redundant and disturbs the symmetry. This also allows you to make the legend itself larger.

    p <- plot(competence_bachelor_plot, centered = FALSE, include.histogram = FALSE) + 
      ggtitle("How do you rate your skills gained with the Bachelor's?*") + 
      theme(axis.text.y = element_text(colour = "black"), axis.text.x = element_text(colour = "black"))+
      theme(legend.key.size=unit(0.02,"npc"))+guides(fill=guide_legend(""))
    

    0 讨论(0)
  • 2021-02-11 05:59

    You could also make the legend two rows, which would create ample room:

    guides(fill = guide_legend(nrow = 2))
    
    0 讨论(0)
  • 2021-02-11 06:09
    p <- plot(competence_bachelor_plot,
              centered = FALSE,
              include.histogram = FALSE) + 
      ggtitle("How do you rate your skills gained with the Bachelor's?*") + 
      theme(axis.text.y = element_text(colour = "black"), 
            axis.text.x = element_text(colour = "black"),
            plot.margin = unit(c(2, 2, 2, 2), "cm"))
    

    enter image description here

    0 讨论(0)
提交回复
热议问题