Приведенные в качестве примера данные и описание желаемого участка ...
- Для type = "death" я просто скопировал данные. Просто в качестве примера.
- Из описания было не совсем понятно, каким должен быть конечный сюжет, например, будет ли показывать разные страны или местоположения.
Поэтому я просто собрал стопку являются графиком кумулятивных случаев по дате и времени. Попробуйте это:
library(ggplot2)
library(dplyr)
dataset <- structure(list(
id = c(
"1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
),
Province.State = c(
"\"\"", "\"\"", "\"\"", "\"\"", "\"\"",
"\"\"", "\"\"", "\"\"", "\"\"", "\"\"", "\"\"", "\"\"", "\"\"",
"\"\"", "\"\"", "\"\"", "\"\"", "\"\"", "\"\"", "\"\""
),
Country.Region = c(
"France", "France", "Germany", "France",
"Germany", "Finland", "France", "Germany", "Italy", "Sweden",
"France", "France", "Germany", "France", "Germany", "Finland",
"France", "Germany", "Italy", "Sweden"
), Lat = c(
47L, 47L,
51L, 47L, 51L, 64L, 47L, 51L, 43L, 63L, 47L, 47L, 51L, 47L,
51L, 64L, 47L, 51L, 43L, 63L
), Long = c(
2L, 2L, 9L, 2L, 9L,
26L, 2L, 9L, 12L, 16L, 2L, 2L, 9L, 2L, 9L, 26L, 2L, 9L, 12L,
16L
), date = structure(c(
18285, 18286, 18288, 18289, 18289,
18290, 18290, 18292, 18292, 18292, 18285, 18286, 18288, 18289,
18289, 18290, 18290, 18292, 18292, 18292
), class = "Date"),
cases = c(
2L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 2L, 1L, 2L, 1L,
1L, 1L, 3L, 1L, 1L, 1L, 2L, 1L
), type = c(
"confirmed", "confirmed",
"confirmed", "confirmed", "confirmed", "confirmed", "confirmed",
"confirmed", "confirmed", "confirmed", "death", "death",
"death", "death", "death", "death", "death", "death", "death",
"death"
), loc = c(
"Europe", "Europe", "Europe", "Europe",
"Europe", "Europe", "Europe", "Europe", "Europe", "Europe",
"Europe", "Europe", "Europe", "Europe", "Europe", "Europe",
"Europe", "Europe", "Europe", "Europe"
), total = c(
2L, 1L,
1L, 4L, 4L, 2L, 2L, 6L, 6L, 6L, 2L, 1L, 1L, 4L, 4L, 2L, 2L,
6L, 6L, 6L
), cumsum = c(
2L, 3L, 4L, 5L, 8L, 9L, 10L, 11L,
13L, 14L, 2L, 3L, 4L, 5L, 8L, 9L, 10L, 11L, 13L, 14L
)
), class = c(
"tbl_df",
"tbl", "data.frame"
), row.names = c(NA, -20L))
dataset_plot <- dataset %>%
# Number of cases by date, type
count(date, type, wt = cases, name = "cases") %>%
# Cumulated sum over time by type
group_by(type) %>%
arrange(date) %>%
mutate(cumsum = cumsum(cases))
ggplot(dataset_plot, aes(date, cumsum, fill = type)) +
geom_area()
![](https://i.imgur.com/GvIOYnd.png)
Создано в 2020-03-18 пакетом Представить (v0.3.0)