【发布时间】:2019-07-16 15:25:00
【问题描述】:
我正在绘制一张热图,我的 y 轴有两个值。相应的垂直年份是可以的(我也想将它们水平放置)但默认情况下,这些年份以一种我无法摆脱的方式出现。如何删除它们并将剩余的年份水平放置?
这是我得到的情节和下面的代码
# Convert months to factors to re-order them, otherwise they will be sorted alphabetically
rates_fed$month <- factor(rates_fed$month, levels=c("Jan", "Feb", "Mar", "Apr", "May", "June",
"July", "Aug", "Sept", "Oct", "Nov", "Dec"))
# Plot the data
rates_fed %>%
group_by(year) %>%
ggplot(aes(rate_fed, x = month, y = year)) +
geom_tile(aes(fill = rate_fed, width = 3, height = 3)) +
geom_text(aes(label = rate_fed), color = "white", size = 4) +
scale_fill_viridis_c("rate", option = "D", limits=c(0.05, 5.5)) +
facet_grid(year~month, scales = "free", space = "fixed", switch = "y")+
theme_minimal(base_family = "mono")+
theme(panel.grid = element_blank(),
axis.text.x = element_text(size = 11), # change the size according to the viz
axis.text.y = element_text(size = 15), # change the size according to the viz
axis.title.x = element_text(size = 15), # change the size according to the viz
axis.title.y = element_text(size = 15), # change the size according to the viz
plot.title = element_text(size = 15)) + # change the size according to the viz
labs(x = "month", y = "year",
title = "Monthly Average Federal Reserve Interest Rates",
caption = "Data: Federal Reserve of St. Louis Bank Data")
【问题讨论】:
-
你的意思是像
theme(axis.text.y = element_blank(), strip.text.y = element_text(angle = 90))这样的吗?
标签: r ggplot2 data-visualization heatmap