0

I have created a nice bubble plot showing sample size at specific lat/lon coordinates using this code;

plot(coastlineWorldFine, clatitude=40.438377, clongitude=-71.476331, span=450) + symbols(bubb$start_lon, bubb$start_lat, circles=bubb$samples, inches=.15, bg="red", add=T)

I can not seem to get the legend to appropriately scale its circle size to cover the range in my dataset, specifically in bubb$samples

Any thoughts on the code I could try?

EDIT, my data looks likes this

    structure(list(start_lat = c(39.267222, 39.32858708, 39.70921237, 
39.90807768, 39.99021857, 39.97938316), start_lon = c(-72.828056, 
-72.76148717, -72.56777679, -72.10185788, -72.03564072, -72.02490474
), samples = c(48L, 41L, 32L, 32L, 23L, 24L)), .Names = c("start_lat", 
"start_lon", "samples"), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))
Thomas
  • 13
  • 4
  • Please make a reproducible example: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – emilliman5 Sep 25 '17 at 21:18

1 Answers1

0

Here is one way of doing it:

library(oce)
library(ocedata)
library(tidyverse)
data("coastlineWorldFine")

bubb <- structure(list(start_lat = c(39.267222, 39.32858708, 39.70921237, 39.90807768, 39.99021857, 39.97938316),
  start_lon = c(-72.828056, -72.76148717, -72.56777679, -72.10185788, -72.03564072, -72.02490474), 
  samples = c(48L, 41L, 32L, 32L, 23L, 24L)), .Names = c("start_lat", "start_lon", "samples"), 
  row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"))

plot(coastlineWorldFine, clatitude=40.438377, clongitude=-71.476331, span=450)
points(bubb$start_lon, bubb$start_lat, cex=bubb$samples/5, pch = 21, col = "black", bg=alpha("red", 0.5))
legend("topright", legend = pretty(bubb$samples/5), pch = 21, pt.cex = 
    pretty(bubb$samples/5), x.intersp = 3, y.intersp = 2, bty = "n", col = "black", pt.bg=alpha("red", 0.5))

enter image description here

Mikko
  • 7,530
  • 8
  • 55
  • 92