轴标签的格式

时间:2019-11-17 16:44:43

标签: r ggplot2 formatting

有人知道要格式化/移动x和y轴标签,使其与轴刻度值名称不重叠吗?

https://i.stack.imgur.com/ft6LV.png

这是我的热图的当前代码:

result<-ggplot(df_matrix, aes(x = flat_type, y = storey_range, fill = median_sales)) + 
      geom_tile() +
      facet_grid(~ estate_type, switch = "x", scales = "free_x", space = "free_x") + 
      scale_y_discrete(limits = rev(levels(as.factor(df_matrix$storey_range))))+
      theme(strip.placement = "top") +
      scale_fill_continuous(labels = dollar) + 
      scale_x_discrete("Flat Type", labels = c ("1 ROOM" = "1 RM", "2 ROOM" = "2 RM", "3 ROOM" = "3 RM", "4 ROOM" = "4 RM", "5 ROOM" = "5 RM", "EXECUTIVE" = "EXEC","MULTI-GENERATION" = "MG"))+ 
      labs(x = "Flat Type", y = "Storey Range",colour = "Average Resale Price ($)",title = "Resale Price By Flat Type and Storey")

2 个答案:

答案 0 :(得分:0)

您可以在theme函数中指定y轴的右边界。

result + theme(axis.title.y = element_text(margin=margin(r=30,"mm")))

答案 1 :(得分:0)

您可以使用document.querySelector('.slick-prev').innerHTML = '<img src="path/to/chevron-left-image.svg">'>; document.querySelector('.slick-next').innerHTML = '<img src="path/to/chevron-right-image.svg">'>; 中的hjustvjust在ggplot中的主题内专门设置轴标题。

element_text