0

I need to plot the Y value 0.1 and 0.2 percentile into the existing scatter plot.Part of the code for the scatter plot as below:

install.packages("ncdf4")
library(ncdf4)
install.packages("ggplot2")
library("ggplot2")
setwd("***ailind")
hp=nc_open("aeob20140910.nc")
hs=nc_open("Ha910L3C_CONUS.nc")
var1_prob<-ncvar_get(hp,"HailProb",verbose=FALSE)
var1_prob[var1_prob==0]<-NA
var2_indx<-ncvar_get(hs,"HailIndx",verbose=FALSE)
var2_indx[var2_indx==0]<-NA
plot(var1_prob,var2_indx,xlim=c(1, 100),ylim=c(1,1000),gridded=TRUE)
var2_indx_0.1<-quantile(var2_indx,0.1)
var2_indx_0.2<-quantile(var2_indx,0.2)

the scatter plot look like this : enter image description here

how to add the y value percentile into the existing scatter plot?

alice
  • 225
  • 5
  • 14
  • It would be great if you could supply a minimal _reproducible_ example to go along with your question. Something we can work from and use to show you how it might be possible to answer your question. That way others can also befit form your question, and the accompanying answer, in the future. You can have a look at [this SO post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to make a great reproducible example in R. – Eric Fail Jan 13 '16 at 21:05

2 Answers2

3

something like this?

require(stats)
qts <- quantile(cars[,2], probs = c(.1, .2))
# qts <- quantile(cars$dist, probs = c(.1, .2)) # alternative method …
require(graphics)
plot(cars)
abline(h = qts, col = "red")

plot with quantile

Eric Fail
  • 8,191
  • 8
  • 72
  • 128
  • @ eric fail what is cars[,2] – alice Jan 13 '16 at 21:21
  • @alice, it's a way _of getting_ to the `dist` variable in the cars data. You asked to _plot the Y value_ hence `[,2]`. If you like you can replace `cars[,2]` with `cars$dist` and get the same result. Look online for a tutorial on _indexing into a data structure_ in R if what I say does not make sense. – Eric Fail Jan 13 '16 at 21:27
  • what is abline(h=qts)? what is h means? – alice Jan 13 '16 at 21:47
  • because when i use that abline. My line is just one straight line at y=0 place. – alice Jan 13 '16 at 21:50
  • It's always harder to help you, and for others to befit form your question, when we don’t have a minimal reproducible example. However, looking at the code you have supplied my guess is that you could could simply add `abline(h = quantile(var2_indx, probs = c(.1, .2)), col = "red”)` after your plot to get what you are looking for. `cars` is a data frame and your data (i.e. `var2_indx’) is not in a data frame (but a vector) – Eric Fail Jan 13 '16 at 22:03
  • what i need is to plot the percentile according to the x value, like every x value what 20% of percentile would be. Your code get a straight line. What i want to achieve is not a straight line. Every x value have a bunch of y value so what is the percentile of y for each x. – alice Jan 14 '16 at 16:34
  • Could you elaborate, or in some way illustrate, the desired behavior you are looking for? Also, I highly recooked that you read [this how to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Eric Fail Jan 14 '16 at 18:08
0

enter image description here

What i want to do is according to different var1_prob, plot the percentile of Var2_indx. such at value 20 for var1_prob what is the 0.05 , 0.1 ,or 0.2 value of var2_indx. i hope this is clear to you @Eric

alice
  • 225
  • 5
  • 14