我正在创建这个图,当我尝试在y轴上对文本进行字符串换行时,问题的顺序变得混乱。如果我不对文本进行换行,它将保持不变。我哪里搞错了?
因此,如果我在代码中使用qtxt4.1,问题是有序的(1-> 17),如果我使用qtxt4.2 (字符串包装文本),问题就不再是有序的。为什么??
qtxt4 <- c("I am fully satisfied with the safety and hygiene measures implemented by the hotel / restaurant(Q1)",
"I fully understand why safety and protection measures must be taken against the Sars-cov-2 virus(Q2)",
"I felt absolutely no threat that I might be infected during my stay at the hotel / restaurant(Q3)",
"I'm not afraid of being infected with the Sars-Cov-2 virus by other hotel / restaurant customers(Q4)",
"I consider that the services offered by the hotel are in full compliance with my expectations(Q5)",
"I am fully satisfied with the safety and hygiene measures in my hotel room(Q6)",
"I am not afraid of being infected with the Sars-cov-2 virus by restaurant / hotel employees(Q7)",
"I certainly would not have chosen this restaurant / hotel if I had another option(Q8)",
"I am convinced that the most effective methods of maintaining safety have been used(Q9)",
"I'm concerned about public health issues(Q15)",
"I am particularly concerned about my health and the health of my family(Q16)",
"I have taken extreme measures for my health and that of my family(Q17)")
qtxt4.1 <- factor(qtxt4, ordered = TRUE, levels = c("I am fully satisfied with the safety and hygiene measures implemented by the hotel / restaurant(Q1)",
"I fully understand why safety and protection measures must be taken against the Sars-cov-2 virus(Q2)",
"I felt absolutely no threat that I might be infected during my stay at the hotel / restaurant(Q3)",
"I'm not afraid of being infected with the Sars-Cov-2 virus by other hotel / restaurant customers(Q4)",
"I consider that the services offered by the hotel are in full compliance with my expectations(Q5)",
"I am fully satisfied with the safety and hygiene measures in my hotel room(Q6)",
"I am not afraid of being infected with the Sars-cov-2 virus by restaurant / hotel employees(Q7)",
"I certainly would not have chosen this restaurant / hotel if I had another option(Q8)",
"I am convinced that the most effective methods of maintaining safety have been used(Q9)",
"I'm concerned about public health issues(Q15)",
"I am particularly concerned about my health and the health of my family(Q16)",
"I have taken extreme measures for my health and that of my family(Q17)"))
qnum4 <- c("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q15","Q16","Q17")
questions4 <- data.frame(qnum4, qtxt4.1)
qtxt4.2 <- stringr::str_wrap(qtxt4.1, width = 35)
questions4 <- data.frame(qnum4, qtxt4.2)
df_c2%>%
pivot_longer(-Studies, names_to = "qnum4") %>%
left_join(questions4, by = "qnum4") %>%
ggplot(aes(value, qtxt4.2)) +
geom_point(aes(color = Studies)) +
labs(x = NULL, y = NULL) +
scale_x_continuous(limits = c(1, 5)) +
theme(text = element_text(size = 12)) +
theme(axis.text = element_text(size = 10))发布于 2021-07-19 21:52:46
在第二个示例中,您需要将qtxt4.2设置为有序因子。一种方法是,使用forcats::fct_reorder是...
questions4 <- data.frame(qnum4, qtxt4.2) %>%
mutate(qtxt4.2 = fct_reorder(qtxt4.2, parse_number(qnum4)))它使用readr::parse_number对qnum4进行数字排序,而不是按字母顺序排序,并使用它对qtxt4.2进行重新排序。这两个包都在tidyverse中。
https://stackoverflow.com/questions/68441557
复制相似问题