[R] Trouble plotting with factor
Paul Johnson
pauljohn at ku.edu
Fri Jan 30 22:04:07 CET 2004
With R 1.8.1 running in Fedora Core 1 Linux, I am having some trouble
recoding and ploting some factor variables.
First, can I give you some example data?
Here is a column of names for age groups:
agegroups <- c( "15-19", "20-24", "25-29","30-34", "35-39",
"40-44","45-49","50-54","55-59","60-64", "65-69", "70-74", "75-79",
"80-84", "OVER")
Here is an index for driver's license ownership in each age group:
fracld
0.4914204
0.9752746
1.0864465
1.0555984
1.0631969
1.0738725
1.0971969
1.0657212
1.0217373
0.9761226
0.9043233
0.9045744
0.8573243
0.7889182
0.5217992
I want to take several similar columns of numbers and put them into a
single line plot, one line for each column.
I can get a graph with the inside part that looks roughly like I want if
I just do:
plot(fracld,type="l")
The horizontal axis, of course, is just the sequence from 1:15, not the
age labels. That's no good.
But, If I try
plot(as.factor(agegroup), fracld, type="l")
the plot does not have the line I want, but rather only flat "steps"
showing the values. It does have a nice looking horizontal axis,
though, showing the age groups.
So I think to myself "I'll outsmart them by adding the lines after
creating the plot", but if I do this
plot(agegroup,fracld,type="n")
The step markers still appear.
So if I want the tick marks and value lables on the horzontal axis,
there is apparently no way to plot lines?
What to do?
More information about the R-help
mailing list