I am trying to plot a graph but the y-axis (the plot is flipped) is getting clipped.
Here is the pdf that my code generates
The SS of the Table_all table
Here is the 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) # To form the table
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))
What I have tried:
- I have tried
scale_y_discrete()
, - Manually setting size,
clip("off")
, (which is still there but it changes nothing).