[R] Pie charts using plotGooglemaps

Boris Steipe boris.steipe at utoronto.ca
Wed Apr 16 00:09:45 CEST 2014


Here you go:

install.packages("plotrix")
library(plotrix)

?floating.pie

dat<- data.frame(x=c(19.9437314, 20.2214171, 20.0955891, 20.9506636),
                 y=c(40.7086377, 41.4924336, 39.9481364, 40.6447347),
                 City=c(120,1, 4, 10),
                 Village=c(425, 1, 4, 15)
                )

# first, set up an existing plot to plot your pies into, for example
plot(c(min(dat$x)-0.5, max(dat$x)+0.5), 
     c(min(dat$y)-0.5, max(dat$y)+0.5), 
     xlab = "", ylab = "", type = "n"
    )

# your pie-chart sectors are rows of the City and Village columns
sectors = cbind(dat$City,dat$Village)

# plot each pie chart in turn
for (i in 1:length(dat$x)) {
    floating.pie(dat$x[i],
                 dat$y[i],
                 sectors[i,],
                 radius=0.1
                )
}

Enjoy,
B.


On 2014-04-15, at 2:43 PM, DrunkenPhD wrote:

> Sorry Jim not for my beginner level :(((
> 
> So if my data are like this :
> 
> x                             y                   City          Village
> 
> 19.9437314          40.7086377          120         425
> 
> 20.2214171          41.4924336          1              1
> 
> 20.0955891          39.9481364          4              4
> 
> 20.9506636          40.6447347          10           15
> 
> how do I plot for every point(x,y) a pie chart with slices(City,Village)?
> Regards
> 
> 
> how do I plot for every point(x,y) a pie chart with slices(City,Village)?
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list