Specific 'shape' symbols appear incorrectly (diamonds vs circles)

100 views
Skip to first unread message

Mauricio

unread,
Apr 18, 2012, 10:39:00 AM4/18/12
to ggplot2
Hello,

Using R 2.14.0, I've written some code that should render points with
a circular shape but that appear as diamonds. The shape codes I'm
using are 1 and 16 ('empty' and 'filled' circles), but what I'm
getting appears more like codes 5 and 18 ('empty' and 'filled'
diamonds).

Any idea as to why this might be? My code is below.

x <- ggplot(mtcars, aes(x=wt, y=mpg, color=factor(am),
shape=factor(gear)))
x <- x + geom_point()
x + scale_shape_manual(values= c('3'= 1, '4' = 16, '5' = 4))

Many thanks,
Mauricio

Winston Chang

unread,
Apr 18, 2012, 11:39:24 AM4/18/12
to Mauricio, ggplot2
I think this was fixed in the development version:
ggplot(mtcars, aes(x=wt, y=mpg, color=factor(am), shape=factor(gear))) + 
  geom_point() + scale_shape_manual(breaks=c(3,4,5), values= c(1,16,4))

Just make sure that the breaks are in ascending order -- there's another bug that's yet to be fixed, where it doesn't work correctly when the breaks are specified in another order.

-Winston



--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Mauricio

unread,
Apr 18, 2012, 2:02:25 PM4/18/12
to ggplot2
Thanks Winston,

I ran the code you suggested ... it didn't work ... got same results
as before. I upgraded R and ggplot2 to latest releases and tried
again ... same results.

You mentioned a fix in the dev version. Is there a way to be notified
when a new 'production' version is available?

-Mauricio


On Apr 18, 11:39 am, Winston Chang <winstoncha...@gmail.com> wrote:
> I think this was fixed in the development version:https://github.com/hadley/ggplot2/issues/264
>
> But you can also use this:
> ggplot(mtcars, aes(x=wt, y=mpg, color=factor(am), shape=factor(gear))) +
>   geom_point() + scale_shape_manual(breaks=c(3,4,5), values= c(1,16,4))
>
> Just make sure that the breaks are in ascending order -- there's another
> bug that's yet to be fixed, where it doesn't work correctly when the breaks
> are specified in another order.https://github.com/hadley/ggplot2/issues/501

Winston Chang

unread,
Apr 18, 2012, 4:32:04 PM4/18/12
to Mauricio, ggplot2
Hm, it's possible that you're running into an issue with non-antialiased graphical output. That is, the shapes are circles, but they may look like diamonds due to poor quality graphical output. Does it look right when you output to pdf?

-Winston

Mauricio

unread,
Apr 18, 2012, 6:59:58 PM4/18/12
to ggplot2
Winston,

You're right. When I output to pdf everything looks fine.
Interestingly enough, I've just tried running the code inside of
RStudio ... and the shapes rendered correctly on screen.
Unfortunately, RStudio other problems with ggplot means I can't use
this option.

Might you know if there's a way to change antialising setting in R?

Many thanks,
Mauricio

Winston Chang

unread,
Apr 19, 2012, 3:57:58 PM4/19/12
to Mauricio, ggplot2
If you output to png using cairo, that should work. If you're using Windows, you might have to install some packages - but I don't a Windows computer so I can't say for sure. Maybe someone else with Windows experience can explain?

png("myfile.png", type="cairo")
# ggplot...
dev.off()

For screen antialiased screen output, on a Mac you can do:
quartz()
# ggplot...

On Linux:
x11(type="cairo")
# ggplot...

Again, on Windows, I'm not sure.

-Winston


Mauricio

unread,
Apr 20, 2012, 10:27:34 AM4/20/12
to ggplot2
Winston,

I am on a Windows computer. When I check the help file for the
'windows()' function, it says that the antialiasing argument only
applies to fonts. Thus it seems that I'll have to output to a file as
you've shown.

Thanks so much for your help on this,
Mauricio
Reply all
Reply to author
Forward
0 new messages