0

I have a data set df1 with 4 columns (see below). I want to visualize the data by temperature (x-axis) and number of tests done at each temperature (y-axis). I also want to see the banding of tests done within each temperature level. I simply can't get it to work:

library(tidyverse)
library(lubridate)

df1 <- tibble::tribble(
  ~date,   ~type2, ~temp, ~tests,
  "09/06/2021", "band_1",  71.5,  4136L,
  "09/06/2021", "band_1",    72, 39656L,
  "09/06/2021", "band_2", 72.25,  1500L,
  "09/06/2021", "band_3",  72.5, 76134L,
  "09/06/2021", "band_1",  72.5, 13715L,
  "09/06/2021", "band_1", 72.75, 10322L,
  "09/06/2021", "band_3", 72.75,  1847L,
  "09/06/2021", "band_1", 72.75,  2277L,
  "09/06/2021", "band_2",    73,    20L,
  "09/06/2021", "band_2",    73,  1836L,
  "09/06/2021", "band_3",    73,  5958L,
  "09/06/2021", "band_1",    73,  5207L,
  "09/06/2021", "band_3",    73, 13542L,
  "09/06/2021", "band_2", 73.25,  1155L,
  "09/06/2021", "band_1", 73.25,   183L,
  "09/06/2021", "band_2", 73.25,  3188L,
  "09/06/2021", "band_3", 73.25,   918L,
  "09/06/2021", "band_2",  73.5,  5342L,
  "09/06/2021", "band_3",  73.5, 16677L,
  "09/06/2021", "band_3",  73.5,   542L,
  "09/07/2021", "band_3", 71.75,  5205L,
  "09/07/2021", "band_2", 71.75,  5444L,
  "09/07/2021", "band_1",    72, 13209L,
  "09/07/2021", "band_3",    72,  2145L,
  "09/07/2021", "band_1",    72,  2315L,
  "09/07/2021", "band_3",    72,    57L,
  "09/07/2021", "band_3", 72.25,   281L,
  "09/07/2021", "band_1", 72.25,   576L,
  "09/07/2021", "band_3", 72.25,   645L,
  "09/07/2021", "band_2",  72.5, 14813L,
  "09/07/2021", "band_3",  72.5,  1964L,
  "09/07/2021", "band_1",  72.5,  1536L,
  "09/07/2021", "band_2",  72.5,  5168L,
  "09/07/2021", "band_3",  72.5,  1986L,
  "09/07/2021", "band_1", 72.75,   990L,
  "09/07/2021", "band_3", 72.75,  2072L,
  "09/07/2021", "band_1", 72.75,  1500L,
  "09/07/2021", "band_2",    73,  3200L,
  "09/07/2021", "band_3",    73, 10923L,
  "09/07/2021", "band_1",    73,  1950L
) %>% 
  mutate(date = mdy(date))


# this is not working
df1 %>% 
  ggplot(aes(x = temp, y = tests) ) +
  geom_col(aes(fill = type2), width = 1) +
  facet_grid(.~date, scales = "free_x")
2
  • 1
    Try removing width = 1, because it causes overlapping Commented Sep 15, 2021 at 20:42
  • Uuups. Vinicius just registered now. Was this comment before my answer? Commented Sep 15, 2021 at 20:45

1 Answer 1

1

Removing width should make it. Are you looking for this solution?

df1 %>% 
    ggplot(aes(x = temp, y = tests) ) +
    geom_col(aes(fill = type2)) +
    facet_grid(.~date, scales = "free_x")

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.