Building a heatmap in R with more information - r

I made a heatmap on R and most of it is one colour. I have two columns of data which showed up as various colours, but the rest of it is red.
Does anyone know how to increase the "resolution" of this? I don't mean anything about how to make the image more clear (which is why I think I'm having trouble searching for info on it). I mean, how do I make my heatmap more meaningful and not all mostly one colour.
Thanks and sorry if this has been answered somewhere else. I think I don't know the key term I need to search properly.
Edit:
Here is the code I used so far (heatdata is my matrix):
heatmap <- heatmap(heatdata,Rowv=NA,Colv=NA,col=cm.colors(256),scale="row")

Related

How do I make gsea plot with group names labelled?

I am trying to plot gsea similar to image as given below:
the tutorial does not give you such plots. So I tried the github link.
But it failed to generate the similar plot
I checked both gseaplot2{enrichplot} and plotEnrichment{fgsea} and found no options to automatically add the group names. It might be a good idea to just add the names after exporting to Adobe Illustrator. Would be happy to hear other ideas though if anyone else knows a better way.

heatmap.2 color legend custom bins

Hi there stackoverflow community!
I am a graduate student inquiring for some consultation on an aethetics R problem I am encountering.
The data I am working with is in the form of a VERY large matrix (49x51).
My problem is that my data ranges from very small to very large, with the bulk of my data falling within the "very large" end of the spectrum, so unless I convert my data to log10, the heatmap is rather boring and almost entirely the same color.
The spectrum of my data is totally within the range I am expecting, but I am hoping to display it in a more aesthetic way.
Proposed solution: I think I need to bin my data in a non-uniform way. If you look at the attached image, you will see that their heatmap looks nice and the color key shows the heat spectrum in a non-fixed bin format. I would like to do something like that, however, I am not sure how to declare cutoffs for each bin. I would ideally like to declare the cutoffs.
For example, bin 1 (0-1), bin 2 (2-50), bin 3 (51-5000). As you can see, my bins would not be fixed in equal increments.
I have been using heatmap.2 for this. Thanks so much in advance!
heatmap with color legend in non-uniform bins:
Hey #Punintended and #S Rivero,
I think I have reached the point that my heatmap will only improve marginally. Both of you contributed deeply to this success, so thanks! First, to condense the matrix values as much as possible, I normalized by column. I was then able to assign gradients. This turned out much better than I had hoped. As you can see, most of my data is clustered (check out the density in the key) at very low values, this is okay though, for I am interested in the higher values. I had to use custom color gradients to account for possible instances of colorblind attendees that might look at my poster. Anyways, if you guys have comments or recommendations, they will be much appreciated :). Again, thanks a bunch!
enter image description here

Creating a grid on a map in R using grid points

I'm clearly struggling with this problem for a day now and can't seem to find a nice solution to it. I would really appreciate some help and I'm really a novice in R (since last week).
Problem 1:
I have a set CSV representing grid points which I can parse into a data frame (pointname, latitude, longitude).
Eg:
name,latitude,longitude
x0y0,35.9767,-122.605
x1y0,35.9767,-122.594
x2y0,35.9767,-122.583
x0y1,35.9857,-122.605
x1y1,35.9857,-122.594
x2y1,35.9857,-122.583
x0y2,35.9947,-122.605
x1y2,35.9947,-122.594
x2y2,35.9947,-122.583
The points in this file represent the lower left corner and are arranged in row major format, meaning lowest horizontal grid points first. Each point is a certain great circle distance away from its neighbors (1km). I want to create a grid overlay on a map which I've plotted using ggmap.
What I've tried or considered:
map.grid() - this is really not useful to me as I'm not looking for any kind of projection.
geom_vline() and geom_hline(). These look good but I don't have constant x and y intercepts on a plane. Moreover, once I create a grid, I'd like to use the grid to color against a density.
geom_rect() and geom_tile(). These look really promising and may be what I want. But I'm not able to find a good way of working with these.
I'd like to fill these grid boxes later with another parameter. Any suggestions on how I can create such a grid? This may be a trivial question but I don't know a lot of R yet.
Problem 2:
How can I store or hold such a grid so that I given a point (lat,lon), I can quickly get to that grid. In fact my whole back end is in C++ and can directly output the grid name x<n>y<n> directly against a given search point. I somehow am finding it difficult to count such points against grid points so that I can fill grid with a representative color.
I'm not sure if everything of what I'm saying is clear. Please tell me if I've to clarify something.
Also note that I've Googled quite a lot and not found relevant answers although some looked close.
Eg: This, ThisToo
Thanks for the help!

Mapping variable values to colors in gvisLineChart?

I'm looking for the equivalent of:
ggplot(df,aes(x=date,y=var1,**group=col1,colour=col1**))+geom_line()
in the googleVis package.
Anyone knows how to do this? I only found examples of differently colored lines if they are mapping different columns from the dataframe.
thanks!
#mtoto, I hope my answer here on ggplot2 equivalent of 'factorization or categorization' in googleVis in R can help. Have you taken a look?
Using roles you can specify specific styles for your data. It involves adding another column with the style detail. So if plotting varx, you need to add the column varx.style where you will set the colors.
I do not know ggplot well enough to know if this is the exact fit of what you want, but please take a look at my figures and links in that answer.

3D plotting in R with categorical data

So I am fairly new to the whole 3D plotting in R thing, and have spent the last day reading up various articles and posts in here and other websites/books. And I have to confess, I am still lost. So any help/advice people can give me will be hugely appreciated!
Ok, so here is my issue (with example data). I have 3 Locations (A-C) sampled for 12 consecutive years (2001-2012) for some measure, with many zeros. So I have this data in a table/matrix/dataframe:
LocationA<-c(0,0,0.83,0.167,0.167,0.083,0.25,0.212,0,0.083,0,0)
LocationB<-c(0,0,0,0,0,0,0,0,0,0.212,0,0)
LocationC<-c(0.633,0.462,0.167,0.467,0,0.167,0.451,0.333,0.462,0.595,0,0)
TestMat<-cbind(LocationA,LocationB,LocationC)
rownames(TestMat)<-c(2001:2012)
What I would like would be similar to a topographical map, with the x-axis being the Location, z-axis the Year, and y-axis the value of the thing I am measuring. I would be potentially open to using bar-plots, but ideally something like wireframe() would be best. I have been messing around with various functions and packages, but I cant quite figure out why what I am doing is not working.
Thank you very much for your help! I am fully aware that I may just be a bit of an idiot and not getting it, so thank you for bearing with me!
Cheers!
EDIT:
So I changed it to a "long-read". The x-values couldnt be non-numeric, so I changed them to x2 (as shown below).
x<-c(rep("LocationA",12),rep("LocationB",12),rep("LocationC",12))
y<-rep(c(2001:2012),3)
z<-c(LocationA,LocationB,LocationC)
x2<-c(rep(1,12),rep(2,12),rep(3,12))
I then used the wireframe() function:
wireframe(z~x2*y,xlab="Location",ylab="Year",zlab="Value",distance=0.4,zoom=0.6,
scales=list(arrows=FALSE,
x=list(at=c(1:3),label=c("A","B","C")),
y=list(at=c(2001:2012),label=c(2001:2012)),
z=list(at=c(0,0.2,0.4,0.6,0.8,1),label=c(0,0.2,0.4,0.6,0.8,1)),
distance=c(2,2,2)),
drape=TRUE)
Now, the thing I cannot figure out, and have been fiddling with, is the colouring. I know that the drape() sub-function allows me to give the lattice a gradient of colour changes, with the higher values showing a different colour to the lower ones. However, I cannot seem to get it to work. It does give me a colour gradation, but the highest value (in this is 0.83) which should be a turquoise colour (the default colour gradient is pink-turquoise - will attempt to change this later), is in fact the colour corresponding to ~0.3 value. There is no error message or warning message attached, and I have no idea why this is happening... Any ideas?
Thanks again! :)

Resources