[R] intensity plot
Jim Lemon
jim at bitwrit.com.au
Tue Sep 17 15:40:02 CEST 2013
On 09/17/2013 07:49 PM, paladini at trustindata.de wrote:
> Hello,
> I have got a data frame looking like this:
>
> Country Sector m-value
>
> USA Banks 38.5
> USA Media 17
> USA hospitals 2.3
> Germany Banks 56
> Germany real estate 1
> Italy Banks 34
> Italy Media 23
> Italy real estate 78
> Italy Beverage 23
> ....
>
>
> I would like to have a graph, let's say country on the x-axis, sector at
> the y-axis, and for
> each compination of country and sector a square in blue. The shade of
> the color should depend on the
> level of the m-value.(This graph should look more or less like the graph
> when you use corrgram() to display correlation)
>
Hi Claudia,
If you can fill in the missing values with NA as below, try this:
cpdat<-read.table(text="USA Banks 38.5
USA Media 17
USA real_estate NA
USA hospitals 2.3
USA Beverage NA
Germany Banks 56
Germany Media NA
Germany real_estate 1
Germany hospitals 5
Germany Beverage NA
Italy Banks 34
Italy Media 23
Italy real_estate 78
Italy hospitals NA
Italy Beverage 23
Australia Banks 15
Australia Media 10
Australia real_estate 42
Australia hospitals NA
Australia Beverage 34")
# create a matrix
cpmat<-matrix(0,nrow=5,ncol=4)
# fill the matrix
for(i in 1:20)
cpmat[as.numeric(cpdat$V2[i]),as.numeric(cpdat$V1[i])]<-cpdat$V3[i]
color2D.matplot(cpmat,extremes=c("blue","red"),axes=FALSE,
main="Intensity plot")
axis(1,at=seq(0.5,3.5),labels=levels(cpdat$V1))
axis(2,at=seq(0.5,4.5),labels=levels(cpdat$V2))
Jim
More information about the R-help
mailing list