1

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"

Thanks.

obl
  • 1,799
  • 12
  • 38
Rigo
  • 11
  • 1

2 Answers2

0

First of all You should read Your question one more time and edit it cause it is very unclear, plus Your code is not editted. As You are a new on stackoverflow please check out this website that is going to give You idea how to ask the question including reproducible example.

Back to Your question:

If you wanna 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"), ]

Additionaly the way You asked the question it has nothing to do with bar plot rather data transformation/filtering.

Mal_a
  • 3,670
  • 1
  • 27
  • 60
0

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

graph = ((barplot(d2[d2$selection_variable <= some_value, ]), ...)
Richard
  • 1,224
  • 3
  • 16
  • 32