Question

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)
Était-ce utile?

La solution

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

Autres conseils

(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")
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top