Brian G
Brian G

Reputation: 11

making polar heat maps in R

Hello I have a set of data (.csv file) that contains distance direction and frequency information in the form of...

      30   60   90   120   150   ...
100  131   12   22   201    66
200   45   83  351   180   210
300   99  121   33     3   306
...

I have some experience with R but am having trouble putting a few graphs together.

I'd like to make a polar plot using the data above. The 'header' (row names) are across the top 30,60,90,etc with the ranges down the first column (100,200,300,etc..) with the intensities being the values of the distance direction combinations, for example 100m @ 30deg = 131 observations.

Any help is greatly appreciated.

Upvotes: 1

Views: 1045

Answers (1)

mnel
mnel

Reputation: 115382

I would get your data in long format, with the rownames as a column, then use ggplot2 and coord_polar

 library(reshape2) 
 library(ggplot2)
 # add rownames a column 'length'
  DT$length <- rownames(DT)
 # make into long format (the value column will be the intensities
  dtlong <- melt(DT)
 # convert from factor column `X30` etc to numeric showing angle
  dtlong$angle <- as.numeric(gsub(dtlong$variable,pattern = 'X',replacement=''))
# use ggplot with coord_polar to make the plot
ggplot(dtlong, aes(x=length,y=angle, size = value)) + 
 geom_point() + 
 coord_polar(theta = 'y')

enter image description here

Upvotes: 1

Related Questions