[R] ggplot2, geom_point with some symbols unfilled

Ista Zahn istazahn at gmail.com
Tue Jan 6 02:20:26 CET 2015


You were close, but a) if you want to map shape to something it needs
to be inside an aes() call, and b) shape 1 is also an open circle. I
think this does what you want:

ggplot(temp,aes(x=lon,y=lat)) +
  geom_point(aes(colour=chlcol, shape=factor(missing)),size=3) +
  scale_colour_gradient(low="lightblue", high="red", na.value="black") +
  scale_shape_manual(values=c(19,1)) + theme_bw()

Best,
Ista

On Mon, Jan 5, 2015 at 6:24 PM, Roy Mendelssohn - NOAA Federal
<roy.mendelssohn at noaa.gov> wrote:
> Hi All:
>
> I have a data frame the first part of which is the following:
>
>          date     lon    lat       mean     chlcol missing
> 1  2003-04-23 203.899 19.664 0.07300000 0.15176637       0
> 2  2003-04-24 204.151 19.821        NaN        NaN       1
> 3  2003-04-30 203.919 20.351 0.07400000 0.15515780       0
> 4  2003-05-01 204.229 20.305 0.06525000 0.12548281       0
> 5  2003-05-02 204.082 20.340 0.04028571 0.04081825       0
> 6  2003-05-03 203.716 20.394 0.08366667 0.18794159       0
> 7  2003-05-04 204.150 20.346 0.02825000 0.00000000       0
> 8  2003-05-05 204.385 20.297 0.05566667 0.09298163       0
> 9  2003-05-07 204.997 20.451        NaN        NaN       1
> 10 2003-05-08 206.066 20.448 0.06533334 0.12576544       0
>
> or from dput:
>
>> dput(temp)
> structure(list(date = structure(c(12165, 12166, 12172, 12173,
> 12174, 12175, 12176, 12177, 12179, 12180), class = "Date"), lon = c(203.899,
> 204.151, 203.919, 204.229, 204.082, 203.716, 204.15, 204.385,
> 204.997, 206.066), lat = c(19.664, 19.821, 20.351, 20.305, 20.34,
> 20.394, 20.346, 20.297, 20.451, 20.448), mean = c(0.0729999989271164,
> NaN, 0.0740000000223517, 0.0652500009164214, 0.0402857145028455,
> 0.0836666661004225, 0.028249999973923, 0.0556666664779186, NaN,
> 0.0653333364365001), chlcol = c(0.151766366071598, NaN, 0.155157797040127,
> 0.125482811598769, 0.040818250276168, 0.187941591833751, 0, 0.0929816299987062,
> NaN, 0.1257654379528), missing = c(0, 1, 0, 0, 0, 0, 0, 0, 1,
> 0)), .Names = c("date", "lon", "lat", "mean", "chlcol", "missing"
> ), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
> "10"), class = "data.frame”)
>
> What I want to do is put a point at each lat-lon location, with the color set by chlcol, except where chlcol is NaN, where I want the point to be a an open circle color black. The variable “missing" is 1 if chlcol is NaN, and zero if not.  So I have tried:
>
>  ggplot(temp,aes(x=lon,y=lat)) + geom_point(aes(colour=chlcol),size=3.,shape=missing) + scale_colour_gradient(low="lightblue", high="red") + scale_shape_manual(values=c(1,21)) + theme_bw()
>
> This gets real close except the missing circles are black and filled, rather than black and open.  A shape value of 21 is suppose to be an open circle.
>
> Thanks for any help.
>
> -Roy
>
> **********************
> "The contents of this message do not reflect any position of the U.S. Government or NOAA."
> **********************
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new address and phone***
> 110 Shaffer Road
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: Roy.Mendelssohn at noaa.gov www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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