1

I cannot find a straightforward way to make a nice image plot in R, but in polar coordinates. I'm basically attempting to find a R equivalent for the 'polarplot3d' function in MATLAB. I've been playing around with ggplot2 package but without much luck. Am I missing a package that contains functionality for what I'm attempting? thanks in advance for any pointers.

Ok, I'm trying to be more clear about what I'm trying to do. Lets say I want to define a polar coordinate grid, increments in the radial direction are 50m and 2.5 degrees in theta. This should look like a dartboard.

My data (r and angle in below code) are correspond to a radial distance measure and an angle. My desired z-value is the counts of a bivariate histogram between r and angle within the increments described above defining the grid.

My data is like the following:

# synthetic data for angle and distance #
angle <- rnorm(500,mean=90,sd=15)
r <- rnorm(500,mean=700,sd=200)

# bivariate histogram #
observations <- table(cut(angle,breaks=c(seq(0,360,by=2.5))),cut(r,breaks=c(seq(0,1400,by=50))))


# the 'z' data are in observations for each bin of bivariate histogram #
# hot to plot a polar coord image? #
  • 1
    `library("sos"); findFn("polar plot")` – Ben Bolker Dec 07 '13 at 16:45
  • Or indeed http://stackexchange.com/search?q=[r]+polar+plot – SlowLearner Dec 07 '13 at 17:26
  • 1
    I think you should realize that your question does not describe the aspects of the pseudo-3d projection that one sees in: http://www.mathworks.com/matlabcentral/fileexchange/13200-3d-polar-plot/content/polarplot3d.m You should make clear what features are needed in the final product. (Pseudo-3d projections do distort the data somewhat so you should be prepared for some resistance to merely replicating that Matlab result, since standing alone it would not appear to be an optimal display of the data.) – IRTFM Dec 07 '13 at 17:53
  • the "sos" was very helpful. I found the openair package that had some nice polarPlot functions. – user3077953 Dec 07 '13 at 19:53
  • You are encouraged to post a solution to your own question if you find something that works well. If the answers below are useful, you may (but are not required to) upvote them; if one of them answers your question adequately you can click the check mark. – Ben Bolker Dec 07 '13 at 19:58

2 Answers2

3

It's very slow to render on my system, but

library(reshape2)
library(ggplot2)
mm <- melt(counts)
ggplot(mm,aes(Var1,Var2,fill=value))+geom_tile()+coord_polar()
ggsave("polar1.png")

appears to work.

enter image description here

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
0

I think the following could work. Use mapproject() from the maproj library to transform my xy coordinates acording to a polar projection (or another), Then use as.image() (from fields package) function to build a image object from my new coordiantes and my Z values. Eventually use image.plot().

library("mapproj")
xyProj <- mapproject(x, y, projection="conic", parameters=-90)
library("fields")
im <- as.image(z, x=xyProj)
image.plot(im)
SESman
  • 238
  • 2
  • 9