Skip to content

Plot complete dataset

2 messages · RMSOPS, Nordlund, Dan (DSHS/RDA)

#
Hello,

     I am a new user of R, so I still have some basic difficulties.
    I'm trying to create a bar graph completely from reading a file.
   The idea was on the x axis have the columns of the table
Married ,Single,Divorced, widower
 the legend Ages
18-34
35-45
46-64
65-69
70-74

the dataset
dataset
   Ages Married Single Divorced widower
1 18-34    10.5   35.7      8.5     3.2
2 35-45    12.4   22.4     22.2    12.6
3 46-64    25.4   22.2     33.4    12.4
4 65-69    36.7   31.4     12.4    35.2
5 70-74    26.4   15.1      8.5    43.2


The code for barplot 

barplot(dataset,dataset$Single, col = c(rainbow(dataset$Ages)), legend =
rownames(dataset$Ages), ylim = c(0, 100))

but I am not able to resolve.

Thanks





--
View this message in context: http://r.789695.n4.nabble.com/Plot-complete-dataset-tp3941346p3941346.html
Sent from the R help mailing list archive at Nabble.com.
#
You should go back and read the help for barplot.  Do you really want to plot the whole dataset (say as a stacked barplot)? Then something like this should do it.

barplot(as.matrix(dataset[,2:5]),  col = c("lightblue", "mistyrose", "lightcyan",
                "lavender", "cornsilk"), 
  legend = dataset$Ages, ylim = c(0, 100))

Your values don't add to 100, so I'm not sure what you actually want.  If this isn't what you want then give us more information.


Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204