J. Cee
J. Cee

Reputation: 49

Keep scale of bubbles consistent across multiple maps using draw.bubble in mapplots?

I am currently drawing a number of bubble plots overlaid onto maps using draw.bubble from packagemapplots. The data consists of animal density for a number of different species in different locations e.g.

Species Density Lat  Lon
A       10      55.4 -7.8
A       12      55.4 -7.7
A       15      55.4 -7.6
B       20      55.4 -7.8
B       22      55.4 -7.7
B       25      55.4 -7.6

etc....

I am drawing a separate map for each species using the following code:

xmin <- min(Data$Long)
xmax <- max(Data$Long)
ymin <- min(Data$Lat)
ymax <- max(Data$Lat)

xlim <- c(xmin,xmax)
ylim <- c(ymin,ymax)

windows()

basemap(xlim, ylim)

draw.bubble(Data$Long[Data$Species=="A"],Data$Lat[Data$Species=="A"],
        Data$Density[Data$Species=="A"], maxradius=0.15, pch=21, bg="#00FF0050")

legend.bubble("bottomright", z=max(Data$Density[Data$Species=="A"]), maxradius=0.15, inset=0.02, bg="lightblue",
          txt.cex=0.8, pch=21, pt.bg="#00FF0050")

The problem I am having is that the size of the bubbles for each separate plot is determined by the largest density value for each species, so when I run this code for multiple species, producing multiple plots the size of the bubbles in each plot is not on the same scale. So I wanted to know if there is anyway that I can specify a consistent scale for the bubbles across all of my plots?

Upvotes: 0

Views: 456

Answers (1)

RHA
RHA

Reputation: 3862

First You need to calculate the maximum of all species

totalmax <- max(Data$Density)

Then, for every plot you calculate the max of that species

speciesmax <- max(Data$Density[Data$Species=="C"])

Calculate the relative bubblesize:

bubblesize = 0.15 * speciesmax/totalmax

And use that in your plot:

draw.bubble(Data$Long[Data$Species=="A"],Data$Lat[Data$Species=="A"],
        Data$Density[Data$Species=="A"], maxradius=bubblesize, pch=21, bg="#00FF0050")

Upvotes: 1

Related Questions