Search code examples
ranalyticsrstudiopie-chart

ERROR: longer object length is not a multiple of shorter object length


I have a dataset which has multiple longitude and latitude of different places in the UK. I am trying to use those figured to create multiple pie charts on the map. Whats essential is just making a pie chart on the map. NOTE: I can make a single pie chart if i hardcode the latitude and longitude.

Code:

floating.pie(xpos = area$longditude,  ypos = area$Latitude,x=1,  radius=0.2, col="orange")

Area:

area <- sqlQuery(con, "SELECT top 3 geo.Latitude, geo.longditude FROM dbo.[Geography]")

The dataset is:

55.9500, 3.1833
54.8659, -2.3522
54.0167, 2.6333
53.5667, 1.2000
52.8311, 1.3278
52.5000, 1.8333
52.3555, -1.1743
51.5000, 51.5000
51.4833, 3.1833
51.3167, 0.5000
50.9600, -3.2200

The error i am getting is:

Warning messages:
1: In cos(t2p) * radius + xpos :
longer object length is not a multiple of shorter object length
2: In sin(t2p) * yradius + ypos :
longer object length is not a multiple of shorter object length

Note: Using all of the above code, i dont get seperate piecharts at all. not sure how to do this, help please. As an example view plotting pie graphs on map in ggplot

What you see in the webpaghe is what i want i ve got it working nearly, just need to know how to tell R to differentiate those values i provide using Area and to plot them correctly as a single pie chart.


Solution

  • I was able to plot multiple float pie charts, but I had to use an infamous for loop.

    area1<-data.frame(Longitude = c(10,30, 50), 
    Latitude = c(5, 25, 50))
    
    plot(0:100,type="n",main="Floating Pie test",xlab="",ylab="",axes=FALSE)
    for(i in 1:length(area1$Longitude)){
        floating.pie(xpos = area1$Longitude[i],  
        ypos = area1$Latitude[i],edges = 200, x=1,  radius=10, col="orange")
    }
    

    enter image description here