I want to create a stacked bar chart in R such that it shows the sum of levels of a feature over time. The feature is of type factor, "char", with levels A, B, H, N, P, U, W. Date feature is type date.
Example data from "chart_df":
char | date |
---|---|
w | 2022-04-09 |
w | 2022-04-07 |
b | 2022-04-06 |
n | 2022-04-05 |
b | 2022-04-03 |
b | 2022-04-03 |
I'm a total beginner. I've tried y= count(), sum(), summarize() with no luck. I've even tried to group by month in hopes that cleaned it up, but it didn't help. I've used this as my guide: https://r-graph-gallery.com/136-stacked-area-chart.html
I can't figure out how to sum the number of chars for a given date(for ex, "b" would have 2 for 2022-04-03). Below is where I'm at so far but it looks awful: enter image description here
library(tidyverse)
library(plotly)
library(ggplot2)
library(viridis)
library(hrbrthemes)
p <- chart_df %>%
ggplot( aes(x=date, y = frequency(char), fill=char, text=char)) +
geom_area() +
scale_fill_viridis(discrete = TRUE) +
theme(legend.position="none") +
theme_ipsum() +
theme(legend.position="top")
# Turn it interactive
p <- ggplotly(p, tooltip="text")
p
I'd like to create a nice, clear and understandable stacked bar chart showing amounts of char for each day over time. Thank you.