ggplot2如何設置x軸的刻度跑到頂框上、
ggplot2如何設置圖例的排列順序、
ggplot2如何對條形圖進行花樣填充、
ggplot2如何取消掉邊框、
ggplot2如何設置圖例到底部、
ggplot2如何去掉圖例的名字、
ggplot2如何去掉網格、
這些在下面的代碼都有體現:
library(tidyverse)library(ggpattern)data.frame('cluster' = rep(paste0('cluster_', 1:5), time = 6), 'type' = rep(paste0('type_', 1:6), time = 5), 'value' = rnorm(n = 30, mean = 0, sd = 1)) %>% ggplot(aes(x = cluster, y = value)) + geom_col_pattern(aes(pattern = type, color = type,fill = type), position = 'dodge', alpha = 0.5) + theme_light() + scale_y_continuous(breaks = seq(from = -2, to = 2, by = 0.6)) + scale_x_discrete(position = "top") + theme(legend.position = "bottom", panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank(), legend.title = element_blank(), panel.border = element_blank() ) + labs(x = "Six-Cluster Model Centroids", y = "Centroids for each cluster")至於ggpattern如何安裝?
看我公眾號文章:
對顏值的追求無止境
如何修改圖例:
https://ggplot2.tidyverse.org/reference/guide_legend.html
當然啦,如果為了學習更多可以看我的ggplot2專輯。
歡迎關注華東吳亦凡