Plotting graphs using R - how to 'omit' specific values?
1
1
Entering edit mode
7.3 years ago
Genosa ▴ 160

Hello, Asking for help from R experts here. I'm totally new in R and I'm just spending lots of time to figure out how to plot scatter plots on R. I have a large data set (>10K rows) which I wish to plot out the data using a scatter plot using this function on the tutorial: http://www.statmethods.net/graphs/scatterplot.html

plot(wt, mpg, main="Scatterplot Example", xlab="Car Weight ", ylab="Miles Per Gallon ", pch=19)

However, my dataset contains many '0' which causes the plot to look strange and wish to have them omitted. How can I do that please? Thanks!

R • 14k views
ADD COMMENT
0
Entering edit mode
7.3 years ago

Most straightforward is to first create a new matrix/dataframe/vector from which you remove those values you don't like. So this problem comes down to subsetting your data container. But make sure to be transparent in these changes, since you are more or less 'manipulating' your data.

ADD COMMENT
1
Entering edit mode

Hi thank you for your reply. However, there are more than 100k 0 values in the data and it's too labour intensive to remove them one by one. Is there another way which I can do this without manipulating data?

ADD REPLY
0
Entering edit mode

You can slice or subset your dataframe, obviously not manually but with an R command.

ADD REPLY
0
Entering edit mode

Hi, Genosa,

is there any function in Microsoft Excel to remove zero values from your matrix before importing it into R ?

~ Best

ADD REPLY
0
Entering edit mode

Doing this in R is one or two lines of code and the solution can easily be found using google or every R tutorial.

ADD REPLY

Login before adding your answer.

Traffic: 1487 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6