user3646105
user3646105

Reputation: 2539

Any way to omit blank cells in a CSV file from plots?

New to R trying to make a simple plot based on two columns of csv data.

Here is the head of the csv

    ID        Value
1 HHK2 -15.87166864
2 HHK2             
3 HHK2             
4 HHK2 -21.56075777
5 HHK2 -16.11445311
6 HHK2  -34.8690159

Here is the plot command, but the plot is incorrect.

library(ggplot2)

raw <- read.csv("mycsv")

ggplot(raw,aes(x=ID,y=Value,color=ID)) + geom_point()

Anyway to tell the plot to ignore the dataframe cells that have no value? If I delete those lines from the .csv then it plots fine.

Upvotes: 1

Views: 1865

Answers (1)

Miff
Miff

Reputation: 7941

If you don't want to plot the rows with blanks, you could use:

ggplot(raw[!is.na(raw$Value),],aes(x=ID,y=Value,color=ID)) + geom_point()

which creates a subset of raw omitting the rows containing NA values caused by reading in blanks, and then uses your plotting command on this.

Upvotes: 1

Related Questions