0

I am trying to produce a map with pie charts laid over the top using draw.pie. I have turned my dataset into an xyz table where:

$x
 [1]   -1.023194 -106.346771  -14.452362  -15.310139   -3.435973   -3.996166  ect ...

$y
 [1]   7.946527  56.130366  14.497401  13.443182  55.378051  17.570692 -14.235004 ect ...

$z
                       1.0 1.1 1.2.1 1.2.2 2.0 2.0.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4
-1.023194, 7.946527      0   0     0     0   0     0   0   1     0     0     0   0     0     0     0     0
-106.346771, 56.130366   0   0     0     1   0     0   1   1     0     0     3   2     0     1     0     2
-14.452362, 14.497401    0   0     0     0   0     0   0   3     0     0     0   0     0     0     0     0

ect...

I would like the pie charts to display the proportion of values in each of the number types, ie. for the pie chart at -1.023194, 7.946527 it would be 100% 2.3, but at -106.346771, 56.130366 it would be divided across 1.2.2,2.2,2.3,2.3.3, 2.4 and 2.4.2.

When I try to run my code I get this error:

Error in map() + draw.pie(z = zaxyz$z, x = zaxyz$x, y = zaxyz$y, radius = 0.3) : 
  non-numeric argument to binary operator

I thought perhpas this was because there were zeros in the table, so I made a trail xyz of :

$x
[1] 22.93751

$y
[1] -30.55948

$z
                      2.3
22.937506, -30.559482   4

But the same message still appears.

I'm very new to R, so this is likely an obvious issue. I'd greatly appreciate if anyone could help me.

Also- is there a way to make the pies on the map proportional to the total number of samples from those coordinates?

Is someone could show me how to do it on a dummy dataset as below...


Latitude   Longitude Number Paratype
12.565679  104.990963      3      2.3
12.565679  104.990963     57    2.3.1
12.565679  104.990963      1    2.4.1
12.862807   30.217636      1      2.3
20.593684   78.962880     14      2.3
20.593684   78.962880     35      2.4
23.684994   90.356331      3    2.4.4

I'd be really grateful. If this table was saved as df.csv, the code I currently have would be as follows:

library(maps)
library(mapdata)
library(maptools)
library(scales)
library(mapplots)
library(dplyr)

df <- data.frame(df.csv)
xyz <- make.xyz(df$Longitude, df$Latitude, df$Number, df$Paratype)
map() +
  draw.pie(z = xyz$z, x = xyz$x, y = xyz$y, radius = 0.3)

(But ideally here, radius = square root of number)

Sorry, I know this is a far from optimal way of presenting this data but I don't understand how to do it any other way.

AliceN
  • 1
  • 1
  • 1
    Welcome to SO, AliceN! Can you please share your sample data using `dput`? Also, please provide code for your plot. See https://stackoverflow.com/q/5963269 for discussions on reproducible questions with usable sample data and code. Thanks! – r2evans Mar 22 '23 at 14:53

0 Answers0