【发布时间】:2020-08-11 09:27:09
【问题描述】:
当我使用 ggplot 创建折线图时,x 轴两侧出现两个间隙,如下所示:
我怎样才能防止这种情况,使线在 x 轴的两个边缘开始和结束,而不是在之前/之后?
这是我到目前为止的代码:
germany_yields <- read.csv(file = "Germany 10-Year Yield Weekly (2007-2020).csv", stringsAsFactors = F)
italy_yields <- read.csv(file = "Italy 10-Year Yield Weekly (2007-2020).csv", stringsAsFactors = F)
germany_yields <- germany_yields[, -(3:6)]
italy_yields <- italy_yields[, -(3:6)]
colnames(germany_yields)[1] <- "Date"
colnames(germany_yields)[2] <- "Germany.Yield"
colnames(italy_yields)[1] <- "Date"
colnames(italy_yields)[2] <- "Italy.Yield"
combined <- join(germany_yields, italy_yields, by = "Date")
combined <- na.omit(combined)
combined$Date <- as.Date(combined$Date,format = "%B %d, %Y")
combined["Spread"] <- combined$Italy.Yield - combined$Germany.Yield
ggplot(data=combined, aes(x = Date, y = Spread)) + geom_line()
【问题讨论】:
标签: r dataframe ggplot2 linechart