我正在尝试在ggplot2的极坐标中创建一个堆积的条形图,但是在保存该图时,文本会被截断。
我尝试过的大多数操作都在ggsave()
语句中,调整高度,宽度和比例参数
为绘图创建数据:
testData <- data.frame(Biome = c(rep('Rainforest', 3), rep('Temperate Forest', 1), rep('Desert', 2), rep('Grassland', 1), rep('Estuary', 3)),
Threat = c(3, 2, 1, 3, 3, 2, 3, 3, 2, 1))
创建情节:
test_plot <- ggplot(testData, aes(x = Biome, y = as.character(Threat), group = Threat, fill = as.character(Threat))) +
geom_bar(stat = 'identity', width = 0.95, colour = 'black', size = 2) +
coord_polar() +
scale_fill_manual(values = c('1' = 'red', '2' = 'darkorange', '3' = 'darkgreen'), labels = c('High', 'Medium', 'Low')) +
labs(fill = 'Ecosystem Threat') +
theme_minimal() +
theme(axis.text.y = element_blank(),
axis.text.x = element_text(colour = 'white', face = 'bold'),
axis.title = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank(),
legend.text = element_text(colour = 'white', face = 'bold'),
legend.title = element_text(colour = 'white', face = 'bold'),
panel.background = element_rect(fill = 'black', colour = NA),
plot.background = element_rect(fill = 'black', colour = NA))
保存情节:
ggsave('~Path~To~Plot', test_plot , dpi = 1200, bg = 'transparent', height = 3, width = 7, units = 'in')
当前,该图在RStudio图查看器中看起来不错,但是在保存时,标签上的某些文本(实际上是轴文本)被画布的边界所截断(左侧的“雨林”,“右侧的“河口”):