2

I have plotted polar coordinates for my data by using ggplot2.

my dataset is in this format:

 Time    Lat    Long   Act
 18:00  21.05   70.00  feed
 18:45  21.00   75.00  walk
 19:00  21.09   77.00  walk
 19:05  24.98   77.09  rest

Code :

library(ggplot2)
plot.new()

ggplot(aes(x = Lat, y = Long, colour = Act), data = file) + 
geom_point() 
ggplot(aes(x= Lat, y = Long , colour = Act), data = file) + 
geom_point() + 
coord_polar(theta = "y")

This is the polar coordinate plot which I get: here

This plot is having latitude and longitude. Now I would like to add one more dimension "time". How can I do this ?. How can I make this 2D polar plot in 3D polar plot ?

  • 1
    You might use shape, size or even an animation (look at the `animation` package). Generally, you should provide a reproducible example: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – lukeA Jun 29 '15 at 07:38

1 Answers1

4

You could try to scale the size of the points with the value of the variable "time". Unfortunately your example is not reproducible, but something along these lines could work:

ggplot(aes(x= Latitude, y = Longitude , colour = ACTIVITY, size=time), data = Data) + geom_point(shape=21) + coord_polar(theta = "y") + scale_size_area(max_size=10)

Below you can see a reproducible example, which is based on data that is used in "The R Graphics Cookbook" by Winston Chang (O'Reilly 2013).

In this case, the dot size represents the temperature, the color refers to a wind speed category, the direction of the wind is plotted in polar coordinates and the radius is the average value of the wind.

library(gcookbook)
library(ggplot2)
p <- ggplot(wind, aes(x=WindDir, y=WindAvg, size=Temp, fill=SpeedCat)) +
     coord_polar() + geom_point(shape=21)+scale_size_area(max_size=10) +
     scale_x_continuous(limits=c(0,360),breaks=seq(0,360,by=45))

This is the output: enter image description here

Hope this helps.

RHertel
  • 23,412
  • 5
  • 38
  • 64
  • Sorry, but I was interested in your answer and can't get it to work. You would help the OP and others by demonstrating your answer and include an output figure. Specifically, your assumptions for "time" seem to be important for it to work correctly to determine size (I got "Error: Discrete value supplied to continuous scale" when this was class `as.Date`). – Marc in the box Jun 29 '15 at 08:36
  • @Marcinthebox My apologies if my tone was unfriendly. I understand your comment much better now. I'll try to see if I can provide a similar plot with one of the common datasets. Presumably, the easiest way to provide a helpful answer would be if the OP could post the output of `dput (Data)`. – RHertel Jun 29 '15 at 09:25
  • @lukeA i have just updated my question. Can you please review that. –  Jun 30 '15 at 11:12
  • @RHertel i have just updated my question. Can you please review that –  Jun 30 '15 at 11:12
  • Thank you, @janvigiri. I'm not sure I can help here. In your revised post you have presented a time series, while I thought that in your example "time" was referring to the duration of each event. To plot your data in a meaningful way it might be necessary to introduce a third dimension and plot the points as a function of (r, phi, and t). At the moment I don't have the time to see if the plot could be modified like this. Maybe later. An alternative would be to plot several polar plots next to each other, each containing data that falls into a different 'bin' of pre-defined time periods. – RHertel Jun 30 '15 at 11:24