简体   繁体   中英

How can I visualise points on a single line in R?

I'm wanting to plot 3 numerical size values on one line in R in order of ascending size, but research so far has pointed me towards regular line graphs. I'm looking for something like this:

在此处输入图像描述

where size increases from left to right and I can plot my 3 data points on the line to show where each sample falls. It doesnt need to be as complicated as this example, just one line standalone. How would I go about doing this?

Here's a quick recreation:

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())

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM