无法使用ggplot2制作折线图,其值缺失[重复]

问题描述 投票:0回答:1

我想制作一个折线图,但这种方式似乎不起作用。只想使用此数据的连续折线图在“ total_index”列中缺少值,但我无法使其正常工作。如果有人做过,请先给我个灯!

我正在尝试到达此图中的两行,但仅适用于“累积”列。需要帮助处理其他专栏。

library(ggplot2)
library(dplyr)

graphdata <- readr::read_csv("animation_cumulative1.csv")

graphplot <- ggplot()+
  geom_line(data=graphdata, aes(x=year, y=total_index), color="Red")+
  geom_point()

print(graphplot)

Data with missing values

Plot result

r ggplot2 graph linegraph
1个回答
0
投票
library(ggplot2) ggplot(subset(df, !is.na(total)), aes(x = year,y = total))+ geom_line()+ geom_point()

enter image description here

数据

structure(list(year = c(1922, 1924, 1929, 1933, 1934, 1945, 1946, 1949, 1954), cum = c(23, 43, 50, 58, 88, 116, 120, 136, 141), total = c(1060, NA, 1232, NA, NA, NA, NA, 1513, NA)), class = "data.frame", row.names = c(NA, -9L))

© www.soinside.com 2019 - 2024. All rights reserved.