Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tidyverse)
- library(ggbeeswarm)
- theme_set(theme_bw())
- # See post here:
- # https://www.reddit.com/r/dataisbeautiful/comments/jidxmm/oc_a_reddit_user_posted_on_rexcel_asking_for_help/ga6aiq1/
- # Iris data:
- p1 <- ggplot(iris) +
- geom_jitter(aes(Species, Sepal.Length),
- width = 0.2,
- color = "steelblue") +
- ggtitle("geom_jitter()")
- p2 <- ggplot(iris) +
- geom_violin(aes(Species, Sepal.Length),
- color = "steelblue") +
- ggtitle("geom_violin()")
- p3 <- ggplot(iris) +
- geom_quasirandom(aes(Species, Sepal.Length),
- width = 0.2,
- color = "steelblue") +
- ggtitle("geom_quasirandom()")
- p1
- p2
- p3
- # Make a 1x3 grid:
- # library(patchwork)
- # P1 <- p1 + p2 + p3
- # P1
- # Rent data:
- # (data is in a two column CSV file with col names `price` and `num_bedrooms`)
- df <- read_csv("bedrooms_price.csv") %>%
- mutate(num_bedrooms = factor(num_bedrooms),
- num_bedrooms = fct_recode(num_bedrooms,
- "Studio" = '0',
- "1 BR" = '1',
- "2 BR" = '2',
- "3 BR" = '3',
- "4 BR" = '4',
- "5 BR" = '5'))
- p1 <- ggplot(df) +
- geom_jitter(aes(num_bedrooms, price),
- width = 0.2,
- color = "steelblue") +
- labs(x = "# of Bedrooms", y = "Monthly Rent ($ CAD)",
- title = "geom_jitter()")
- p2 <- ggplot(df) +
- geom_violin(aes(num_bedrooms, price),
- color = "steelblue") +
- labs(x = "# of Bedrooms", y = "Monthly Rent ($ CAD)",
- title = "geom_violin()")
- p3 <- ggplot(df) +
- geom_quasirandom(aes(num_bedrooms, price),
- width = 0.2,
- color = "steelblue") +
- labs(x = "# of Bedrooms", y = "Monthly Rent ($ CAD)",
- title = "geom_quasirandom()")
- p1
- p2
- p3
- # Make a 1x3 grid:
- # library(patchwork)
- # P1 <- p1 + p2 + p3
- # P1
Add Comment
Please, Sign In to add comment