how to make the shape thicker in the scatterplot

2,546 views
Skip to first unread message

cynthiashuang

unread,
May 24, 2014, 10:51:22 AM5/24/14
to ggp...@googlegroups.com
Hi all,

How to make the shape thicker in ggplot? I manually choose shape value = 1,2,3,4. But I cannot find a parameter in ggplot to adjust/tune the thickness of the marker. Is there any straight forward way to do it?

Below is my program.

  p <- ggplot(test, aes(y=y, x=x, 
                               colour=a_b, shape=a_b)) + 
    geom_point(position=position_jitter(width=0.2, height=0.1), na.rm = TRUE) + 
    
    xlab("Baseline X") + ylab("% Y Change from Baseline") + scale_colour_discrete(name  ="A:B") + scale_shape_manual(values=c(1,2,3,4), name ="A:B") +

#theme with white background
theme_bw() +
  
  #eliminates background, gridlines
  theme(
    plot.background = element_blank()
    ,panel.grid.major = element_blank()
    ,panel.grid.minor = element_blank()
  )  

Thanks,
Cynthia
test.pdf

Phillip Burger

unread,
Jun 17, 2014, 7:23:58 PM6/17/14
to ggp...@googlegroups.com
Hi, Cynthia.  The attachment does not contain any content.  I can download the attachment and open it, but there is not sample plot or other information. If you still have the question and can post the sample plot to provide further, please attach it and I or another member in the group will try to help.

-Phil

Dennis Murphy

unread,
Jun 18, 2014, 1:12:08 AM6/18/14
to cynthiashuang, ggplot2
Hi:

Thankfully, this thread was resurrected so I'll give it a shot. This
should get you close to what you want. Using a simple toy example,

DF <- data.frame(x = rnorm(30), y = rnorm(30),
gp = sample(LETTERS[1:4], 30, replace = TRUE))

library(ggplot2)
library(grid)

p <- ggplot(DF, aes(x, y)) +
geom_point(aes(shape = gp, fill = gp), size = 3.5,
color = "black") +
scale_shape_manual(values = 21:25)

grid.edit("geom_point.points", grep = TRUE, gp = gpar(lwd = 2))


Notes:

1. Shapes 21-25 allow fill color, which explains the choice in
scale_shape_manual().
2. To thicken the line borders, you need to use grid graphics
directly. This is what the last line does, which comes from a
StackOverflow question answered by Sandy Muspratt in August, 2013:
http://stackoverflow.com/questions/17677687/change-thickness-of-a-marker-in-ggplot2
3. You need to fix the point color before you can thicken the shape
borders; clearly, you want the border color to differ from the fill
color unless you want to play with alpha transparency, which is
another option..
4. I know the next question is going to be how to make the border
thickness in the legend the same as that in the graph. I tried without
success. It probably involves some combination of guide_legend() with
the override.aes argument and some appropriate incantation from grid
graphics, but I don't know enough about the latter yet to make it
work. Perhaps someone else can fill the gap.

Dennis
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages