Deleted variable in a barplot

57 Views Asked by At

I need your help with a barplot in R.

I have a data frame called "answers", it is something like this:

v0= Chicago, Miami,Orlando, New York, (50 cities more)
v1= employee, Unemployed, looking for a job .

I need help with a barplot, I'm doing this:

  1. for my first column a1=answers[,c("v0")] b1=table(a1)

  2. For my second column a2=answers[,c("v1")] } b2=table(a2)

Then I match both tables in just one:

d=table(a2,b2) d1=prop.table(d, margin=2) d2=percent(d1,digits = 3) the result show me the number of person employees, unemployees and looking for a job in each city.

Finally i make a barplot: graph=barplot((d2),las=1,beside=T, horiz=F,ces.names=1.5,col=..........)

My question is:

How can I delete one or more options from V2, that means just make a barplot about the results for "employee" and "nonemployee" and remove "looking for a job"

2

There are 2 best solutions below

0
On

If you want to just remove the rows of your data frame which consist of the variable value = "looking for job", You can easily use this piece of code:

data <- data.frame(
  v0 = c("employee", "Unemployed", "looking for a job"),
  v1 = c("Chicago", "Miami","Orlando"))

data <- data[!data$v0 %in% c("looking for a job"), ]
0
On

You can do so by subsetting the data.frame. For example:

graph = ((barplot(d2[d2$selection_variable <= some_value, ]), ...)