绘图轴超出边界

时间:2020-10-29 15:50:42

标签: r ggplot2

我正在尝试绘制图形,但是y轴(图表已翻转)被裁剪。

这是我的代码生成的pdf
Here is the pdf that my code generates

Table_all表的SS
The SS of the Table_all table

这是MWE:

x <- read.table("Table_all.txt", sep = "\t", header = TRUE, 
stringsAsFactors=TRUE) 

x$Types <- factor(x$Types, levels = x$Types[order(x$Percentage)]) # To order

p <- ggplot(x, aes(x = Types, y = Percentage))+ theme_classic() +
theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
panel.grid.minor = element_blank(),
axis.text.x=element_text(size=16, color = "black", family = "Linux 
Libertine"), 
axis.text.y=element_text(size=16, color = "black", family = "Linux 
Libertine"),
axis.line.y = element_line(color="black", size = 0.5)) + 
geom_col(fill = "steelblue") + coord_flip(expand = FALSE, clip = 'off') + 
geom_text(aes(label=sprintf("%0.1f %%", Percentage), fontface = "bold", 
family = "Linux Libertine"), vjust=0.5, hjust=-0.2, color="black", 
size=4.2)+
xlab("") + ylab("") + ylim(0,60)

ggsave(p, filename = "whatever.pdf", device = cairo_pdf, dpi = 300)

dput(x)#组成表格

structure(list(Types = structure(c(9L, 5L, 7L, 6L, 10L, 3L, 4L, 
8L, 2L, 1L, 11L), .Label = c("Account Management", "Allocation of 
Resources", 
"Audit Review And Analysis", "Authenticator Management", "Boundry 
Protection", 
"Identification & Authentication", "Least Functionality", "Least 
Privilege", 
"Others", "Physical Access Control", "Remote Access"), class = "factor"), 
Percentage = c(54.1, 13.4, 6, 5.1, 4, 3.7, 3.4, 2.9, 2.7, 
2.4, 2.3)), class = "data.frame", row.names = c(NA, -11L))

我尝试过的事情:

  • 我尝试过scale_y_discrete()
  • 手动设置尺寸
  • clip("off"),(它仍然存在,但没有任何改变)。

0 个答案:

没有答案