0

I want to visualize/plot data with a color scale represents the value in the GIC.Fish and GIC. Zoop columns by Dive.Number. This is somewhat like a correlation matrix or heat map, except that the Fish and Zoop values are not related to one another, but are related to the dive number. The following data is a data frame "temp".

Dive.Number GIC.Fish GIC.Zoop
 [1,]           1     0.83     0.37
 [2,]           2     0.88     0.41
 [3,]           3     0.98     0.57
 [4,]           4     0.90     0.43
 [5,]           5     1.00     0.58
 [6,]           6     0.92     0.44
 [7,]           7     0.71     0.33
 [8,]           8     0.99     0.55
 [9,]           9     0.94     0.47
[10,]          10     0.95     0.48
[11,]          11     0.91     0.44
[12,]          12     0.96     0.50
[13,]          13     0.86     0.39
[14,]          14     0.94     0.47
[15,]          15     0.91     0.43
[16,]          16     0.89     0.41
[17,]          17     0.92     0.45
[18,]          18     0.94     0.47
[19,]          19     1.00     0.59
[20,]          20     0.96     0.53
[21,]          21     0.96     0.52
[22,]          22     1.00     0.68
[23,]          23     0.99     0.73
[24,]          24     0.98     0.77
[25,]          25     0.96     0.80
[26,]          26     0.83     0.98
[27,]          27     0.72     1.00
[28,]          28     0.98     0.77
[29,]          29     0.44     0.73
[30,]          30     0.29     0.44
[31,]          31     0.31     0.48
[32,]          32     0.64     0.97
[33,]          33     0.08     0.04
[34,]          34     0.09     0.05
[35,]          35     0.61     0.96
[36,]          36     0.36     0.59

This code gets me somewhat close, but with only one column of relevant data.

    p<-ggplot(temp, aes(x=GIC.Fish, y=Dive.Number, fill=GIC.Fish))+
    geom_tile() +
    scale_fill_gradient2(midpoint=.5, low="blue", high="red") +
    guides(fill=FALSE)

This gets me even closer, but I don't want a column for Dive Number, nor do I want to show the actual values in the cells and I'd like to be able to change the colors in the colorbar.

setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
    source(con)
close(con)
as.matrix(temp)
plot.table(temp, highlight=TRUE, colorbar=TRUE)
akbreezo
  • 115
  • 1
  • 1
  • 10
  • Can you please try to describe what this plot would look like? What is on each axis, and what is colour meant to represent? – alexwhan Jul 01 '13 at 23:15
  • I would like the x-axis to the Fish and the Zoop values (almost like two columns or frames) and the y-axis to be the dive numbers. The color is meant to represent the values in Fish and Zoop on a scale from blue (values of zero) to red (values of 1). Does that help? – akbreezo Jul 02 '13 at 00:41

2 Answers2

1

Is this the sort of thing you're after? Assuming your data is dat:

dat$Dive.Number <- factor(dat$Dive.Number)
library(reshape2)
dat.m <- melt(dat, variable.name = "GIC.type", value.name = "GIC")

p <- ggplot(dat.m, aes(GIC, Dive.Number)) + geom_point(aes(colour = GIC)) +
  scale_colour_gradient(low = "blue", high = "red") +
  facet_wrap(~GIC.type)
p

enter image description here


EDIT

Based on your comments, maybe this is more like what you're imagining:

p <- ggplot(dat.m, aes(GIC.type, Dive.Number)) + geom_tile(aes(fill = GIC)) +
  scale_fill_gradient(low = "blue", high = "red")

enter image description here

alexwhan
  • 15,636
  • 5
  • 52
  • 66
  • It's close, but I'd like it to be more compact, such that values are contained in a single column rather than across the spread of values. So, it would actually look more like a table with colored cells. – akbreezo Jul 02 '13 at 01:01
  • So how would you know what is from GIC.Fish and what is from GIC.Zoop? – alexwhan Jul 02 '13 at 01:03
  • Yes, this looks great. I'll apply it to the full dataset tomorrow and see how it goes. Thanks for the comeback and sorry if my descriptions were very clear. – akbreezo Jul 02 '13 at 04:48
  • Just ran this through my data. Looks sharp! – akbreezo Jul 02 '13 at 18:10
0

(caveat. Not a ggplot2 creation. I never learned to think with that model.)I thought you might be looking for a 2d-density map that could be color coded so I plotted GIC.Zoop against GIC.Fish. The notion of generating a density map from that result didn't seem to fit the pattern of the data, so I drew lines to see if there were an apparent sequence. I then labeled the points by Dive.Number which was coded by color:

 plot(GIC.Fish ~ GIC.Zoop, data=dat, ylim=c(0,1.1) )
 with(dat,  lines(GIC.Fish ~ GIC.Zoop) )
 with(dat, text(GIC.Zoop, GIC.Fish+.05, labels=Dive.Number , 
           col= colorRampPalette( c("#FFFFD4", "#FED98E", "#FE9929", 
              "#D95F0E", "#993404"), space = "Lab")(36)[Dive.Number]) )

enter image description here

You can experiment with the color transitions. This color vector give more contrast:

 c("#00FFD4", "#00D98E", "#880088", "#D900ff", "#993404")
IRTFM
  • 258,963
  • 21
  • 364
  • 487