Skip to content

Barplot With Selected X-Axis Region

2 messages · Gundala Viswanath, Uwe Ligges

#
Dear all,

I have a data that looks like this:
V1   V2
1     -43342073   14
2     -43337730    4
3     -43284676    1
....
11372  75188572   11
11373  75206165    6
11374  75262720   24


What I want to do is to have a barplot where x-axis
is taken from V1 and y-axis taken from V2.

But I only want to plot the those region where V1 >= -500
and <= 500.

But some how this snippet doesn't seem to work:
What's wrong with my approach.

So yes, I do want the V1 information, hence I am aware that
I dont' want:
- Gundala Viswanath
Jakarta - Indonesia
#
Gundala Viswanath wrote:
You need to change

dat$V1 >= -500 && dat$V1 <=500

to

dat$V1 >= -500 & dat$V1 <=500

and read about the difference between & and &&.


So probably you want something like:

   subsetdat <- dat[dat$V1 >= -500 & dat$V1 <=500,]
   barplot(subsetdat$V2, names.arg=subsetdat$V1)

Uwe Ligges