R 在ggplot2极坐标中使用画布剪裁标签
我试图在ggplot2中创建极坐标的堆叠条形图,但在保存绘图时,文本被截断了 我尝试的大部分内容都是在R 在ggplot2极坐标中使用画布剪裁标签,r,ggplot2,polar-coordinates,R,Ggplot2,Polar Coordinates,我试图在ggplot2中创建极坐标的堆叠条形图,但在保存绘图时,文本被截断了 我尝试的大部分内容都是在ggsave()语句中,调整高度、宽度和比例参数 为绘图创建数据: testData <- data.frame(Biome = c(rep('Rainforest', 3), rep('Temperate Forest', 1), rep('Desert', 2), rep('Grassland', 1), rep('Estuary', 3)),
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))
目前,绘图在RStudio绘图查看器中看起来很好,但保存时,标签上的一些文本(实际上是轴文本)会被画布的边界切断(“雨林”在左侧,“河口”在右侧):
您是否考虑过将您的
coord\u polar()
替换为coord\u polar(clip=“off”)
?谢谢您的建议。在发布这个问题之前,我没有试过。我刚刚运行了,但没有成功。我也运行了您的代码,但是当使用clip=“off”
时,.png似乎很好。
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')