My goal is to place the border around points in scatter plot
WHICH has the gradient color and gradient shape based on the value (as you can see in following script).
ggplot(filname, aes(Va1, Var2, col= PR, size=PR)) +
geom_point() +
labs(list(title = "Title", y = "Var2", x = "Var1")) +
xlim(0, 150) +
scale_color_gradientn(colours = rainbow(7)) +
scale_x_continuous(breaks=seq(0, 150, 12))
** PR is the third Var in my data.
I found the following questions here:
but really they do not work in my case due to the two reasons I bolded above, I want to keep the gradient color and gradient shape but at the same time add the border around the points to make them more appreciable.
Basically, to make outline colour in ggplot I found we would have :
Considering this when I act accordingly as below
ggplot(PR_Grt100_REL_80, aes(Age, SC, col= PR, size=PR)) +
geom_point(aes (fill= PR), colour = "black") +
labs(list(title = "Title", y = "Var2", x = "Var1")) +
xlim(0, 150) +
scale_color_gradientn(colours = rainbow(7)) +
scale_x_continuous(breaks=seq(0, 150, 12))
I would get the following graph!
Any help is highly appreciated?
I think all you need to do is to use a shape that respects fill
and color
. Shapes 21:25 have this property, http://sape.inf.usi.ch/quick-reference/ggplot2/shape .
Using mtcars
:
library(ggplot2)
ggplot(mtcars, aes(mpg, hp, fill = cyl, size = cyl)) +
geom_point(shape = 21, stroke = 2) + # change the thickness of the boarder with stroke
scale_fill_gradientn(colours = rainbow(7)) +
scale_size(range = c(2,6)) # only for example visibility
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.