我有一个数据集,其中包含多个NA值.绘制此数据时,ggplot的geom_line()选项可以跨NA值连接线.有没有办法让ggplot跳过跨越NA值的线?
编辑:向所有参与者致歉.我在操纵数据框时犯了一个错误.我想出了我的问题.当我创建子集时,我的x轴不连续.缺少的数据没有被NA替换,因此数据被链接,因为在行之间的子集中没有创建NA.
Dre*_*een 12
geom_line确实为列中的NAs 创建了中断y,但它连接NA了x列中的值.
# Set up a data frame with NAs in the 'x' column
independant <- c(0, 1, NA, 3, 4)
dependant <- 0:4
d <- data.frame(independant=independant, dependant=dependant)
# Note the unbroken line
ggplot(d, aes(x=independant, y=dependant)) + geom_line()
Run Code Online (Sandbox Code Playgroud)

我假设你的NA价值观在你的as.POSIXlt(date).如果是这样,一种解决方案是将NA值映射到列y,然后用于coord_flip使y轴水平:
ggplot(d, aes(x=dependant, y=independant)) + geom_line() +
coord_flip()
Run Code Online (Sandbox Code Playgroud)

大概你的代码是:
ggplot(crew.twelves, aes(x=laffcu, y=as.POSIXlt(date)) + geom_line() +
coord_flip()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5599 次 |
| 最近记录: |