[R] type of representation

Warnes, Gregory R gregory_r_warnes at groton.pfizer.com
Fri Jan 3 18:54:05 CET 2003


How about this snippet:

# Create an Example Data Frame Containing Car x Color data
carnames <- c("bmw","renault","mercedes","seat")
carcolors <- c("red","white","silver","green")
datavals <- round(rnorm(16, mean=10, sd=4),1)
data <- data.frame(Car=rep(carnames,4),
                   Color=rep(carcolors, c(4,4,4,4) ),
                   Value=datavals )
# show the data
data

# plot the Car x Color combinations, using 'cex' to specify the dot size
plot(x=codes(data$Car),     # codes give numeric values
     y=codes(data$Color), 
     cex=data$Value/max(data$Value)*12,  # standardize size to (0,12)
     pch=19,  # filled circle
     col="skyblue", # dot color
     xlab="Car", # x axis label
     ylab="Color", # y axis label
     xaxt="n", # no x axis lables
     yaxt="n", # no y axis lables
     bty="n",  # no box around the plot
     xlim=c(0,nlevels(data$Car  )+0.5), # extra space on either end of plot
     ylim=c(0.5,nlevels(data$Color)+1.5)  # so dots don't cross into margins
     )

# add text labels
text(x=1:nlevels(data$Car), y=nlevels(data$Car)+1, labels=levels(data$Car))
text(x=0, y=1:nlevels(data$Color), labels=levels(data$Color) )

# add borders between cells
abline(v=(0:nlevels(data$Car)+0.5))
abline(h=(0:nlevels(data$Color)+0.5))

# annotate with actual values
text(x=codes(data$Car),     # codes give numeric values
     y=codes(data$Color), 
     labels=format(data$Value),       # label value
     col="black", # textt color
     )

# put a nice title
title(main="Car by Color Popularity\n(Dot size proportional to popularity)")


-Greg

> -----Original Message-----
> From: allende at gredos.cnb.uam.es [mailto:allende at gredos.cnb.uam.es]
> Sent: Friday, January 03, 2003 4:46 AM
> To: r-help at stat.math.ethz.ch
> Cc: allende at gredos.cnb.uam.es
> Subject: [R] type of representation
> 
> 
> Hi
> 
> I have some data that i want to plot but i don't find how to 
> do it. I have car
> types (bmw,renault,mercedes,seat ...), colors and a number 
> for each car
> type-color relation.I want to come up with a matrix 
> representation of cars vs
> colors where in each intersection i could set a dot 
> proportional in size to my
> third variable.
> 
> 
> Can anybody give me a clue of hoe to come up with such representation.
> 
> Thanks
> 
> Ramon
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 


LEGAL NOTICE\ Unless expressly stated otherwise, this message is ... [[dropped]]




More information about the R-help mailing list