-2

I wanted to make a line graph but it doesn't seem to work this way. Just want a continuous line graph with this data that has missing values in the column "total_index", but i can't get it to work. If anybody has done it before give me a light please!

I'm trying to get to two lines in this graph, but it only works with the "cumulative" columns. Need help handling the other column.

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

Axeman
  • 32,068
  • 8
  • 81
  • 94
luka1156
  • 181
  • 1
  • 8
  • Have you seen [this question](https://stackoverflow.com/questions/28775036/ggplot-line-graph-with-na-values)? – jazzurro Jan 16 '20 at 01:29

1 Answers1

0

You should subset your dataframe for removing NA before plotting

library(ggplot2)
ggplot(subset(df, !is.na(total)), aes(x = year,y = total))+
  geom_line()+
  geom_point()

enter image description here

Data

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))
dc37
  • 15,840
  • 4
  • 15
  • 32
  • Thanks for the help, man! Is there a fast way to make theses lists with all the values in the .csv or did you do it by hand? – luka1156 Jan 16 '20 at 02:29
  • Already did it with Python! – luka1156 Jan 16 '20 at 02:49
  • Not a list, but a concatenation function like this: "c(1060, NA, 1232, NA, NA, NA, NA, 1513, NA)". I made a program in python to print the columns of the .csv as a list an then just copied into this c() function. – luka1156 Jan 16 '20 at 16:13
  • I'll check the recommendations man. Thanks a lot! – luka1156 Jan 16 '20 at 16:14