如何可视化 R 中单条线上的点?
How can I visualise points on a single line in R?
我想在 R 中的一条线上按大小升序绘制 3 个数值大小值,但到目前为止的研究使我倾向于使用常规线图。我正在寻找这样的东西:
其中大小从左到右增加,我可以在线上绘制我的 3 个数据点以显示每个样本的位置。它不需要像这个例子那么复杂,单独一行就可以了。
我该怎么做?
这里有一个快速的娱乐:
library(tidyverse)
mtcars %>%
group_by(gear = as.factor(gear)) %>%
summarize(min = min(wt),
max = max(wt),
mean = mean(wt),
sd = sd(wt),
median = median(wt)) -> summary
ggplot(summary, aes(y=gear)) +
geom_errorbarh(aes(xmin = min, xmax = max), height = 0.04, color = "gray70") +
geom_segment(aes(yend = gear, x = mean-sd, xend = mean+sd), alpha = 0.3,
color = "forestgreen", size = 10) +
geom_point(aes(x = median), shape = 17, color = "darkred") +
geom_text(aes(x = median, label = median), vjust = -1.5) +
theme_minimal() + theme(panel.grid = element_blank())
我想在 R 中的一条线上按大小升序绘制 3 个数值大小值,但到目前为止的研究使我倾向于使用常规线图。我正在寻找这样的东西:
其中大小从左到右增加,我可以在线上绘制我的 3 个数据点以显示每个样本的位置。它不需要像这个例子那么复杂,单独一行就可以了。 我该怎么做?
这里有一个快速的娱乐:
library(tidyverse)
mtcars %>%
group_by(gear = as.factor(gear)) %>%
summarize(min = min(wt),
max = max(wt),
mean = mean(wt),
sd = sd(wt),
median = median(wt)) -> summary
ggplot(summary, aes(y=gear)) +
geom_errorbarh(aes(xmin = min, xmax = max), height = 0.04, color = "gray70") +
geom_segment(aes(yend = gear, x = mean-sd, xend = mean+sd), alpha = 0.3,
color = "forestgreen", size = 10) +
geom_point(aes(x = median), shape = 17, color = "darkred") +
geom_text(aes(x = median, label = median), vjust = -1.5) +
theme_minimal() + theme(panel.grid = element_blank())