我有以下代码,它可以毫无问题地绘制,除了我只显示第一个标签并且它位于右下角而不是行尾。我哪里出错了?
p1 <- ggplot() +
geom_line(data = data.cn, aes(dateRep, cumsum(deaths),colour = geoId)) +
geom_line(data = data.uk, aes(dateRep, cumsum(deaths),colour = geoId)) +
geom_line(data = data.it, aes(dateRep, cumsum(deaths),colour = geoId)) +
geom_line(data = data.es, aes(dateRep, cumsum(deaths),colour = geoId)) +
geom_line(data = data.us, aes(dateRep, cumsum(deaths),colour = geoId)) +
geom_line(data = data.tr, aes(dateRep, cumsum(deaths),colour = geoId)) +
xlab('Date') +
ylab('Deaths') +
gghighlight(TRUE, label_key = geoId, use_direct_label = TRUE,
label_params = list(segment.color = NA, nudge_x = 1))
编辑
获取数据的完整代码
library(httr)
library(dplyr)
library(tidyverse)
library(ggplot2)
library(tidyr)
library(gghighlight)
GET("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv", authenticate(":", ":", type="ntlm"), write_disk(tf <- tempfile(fileext = ".csv")))
data <- read.csv(tf)
data$geoId <- as.character(data$geoId)
data$dateRep <- as.Date(data$dateRep, "%d/%m/%Y")
data.cn <- subset(data, geoId == "CN") %>% arrange(dateRep)
data.it <- subset(data, geoId == "IT") %>% arrange(dateRep)
data.uk <- subset(data, geoId == "UK") %>% arrange(dateRep)
data.es <- subset(data, geoId == "ES") %>% arrange(dateRep)
data.us <- subset(data, geoId == "US") %>% arrange(dateRep)
data.tr <- subset(data, geoId == "TR") %>% arrange(dateRep)
data.nl <- subset(data, geoId == "NL") %>% arrange(dateRep)
data.aus <- subset(data, geoId == "AU") %>% arrange(dateRep)