[英]making the y-axis text smaller in r
I have this code:我有这个代码:
df5 %>%
pivot_longer(-Varsta, names_to = "qnum") %>%
left_join(questions2, by = "qnum") %>%
ggplot(aes(value, qtxt2)) +
geom_point(aes(color = Varsta)) +
labs(x = NULL, y = NULL) +
scale_x_continuous(limits = c(1, 5))`
I am trying to make the text smaller and the graph bigger.我正在尝试使文本更小,图形更大。 How do you do that??
你是怎样做的??
Reproducing the issue:重现问题:
my_data <- data.frame(qtxt2 = paste(1:9,
"really long label that has many words that",
"are taking up too much space in my plot"),
value = runif(9, min = 1, max = 5))
library(ggplot2)
ggplot(my_data, aes(value, qtxt2)) +
geom_point() +
labs(x = NULL, y = NULL) +
scale_x_continuous(limits = c(1, 5))
One solution is to shrink the y axis text:一种解决方案是缩小 y 轴文本:
ggplot(my_data, aes(value, qtxt2)) +
geom_point() +
labs(x = NULL, y = NULL) +
scale_x_continuous(limits = c(1, 5)) +
theme(axis.text.y = element_text(size = 6))
It might be more effective here to use text wrapping to split the labels onto multiple lines.在这里使用文本换行将标签拆分为多行可能更有效。
my_data$qtxt3 = stringr::str_wrap(my_data$qtxt2, width = 30)
ggplot(my_data, aes(value, qtxt3)) +
geom_point() +
labs(x = NULL, y = NULL) +
scale_x_continuous(limits = c(1, 5))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.