r - Draw points 1 size bigger than the line size -


i draw plot in ggplot using stat_summary() geom="line" , geom="point"

for use following function:

drawplot <- function(...) ggplot2::ggplot(...) +    stat_summary(fun.y=mean, geom="line" ) +    stat_summary(fun.y=mean, geom="point" ) +   scale_size_manual(values = c(0.5, 0.8, 1.2, 2, 3, 4, 5) )  

with function when do:

drawplot(data = metric_sum, aes(x = x_metric, y=summedvalue, size=as.factor(clusteringdistance)))  

i plot has lines different sizes, , no points @ all.


instead have plot lines have dots well, , dots 1 size bigger line itself, noticeable.

i believe achieved drawing each plot separately (not using drawplot function) , doing aes stat_summary(geom="point").

is possible achieve same within drawplot function?

the points being plotted, same color , size lines, can't see them. can see in following example code altered use built-in mtcars data frame. lines , points plotted in different colors , points visible:

drawplot <- function(...) ggplot2::ggplot(...) +    stat_summary(fun.y=mean, geom="line", colour="grey40") +    stat_summary(fun.y=mean, geom="point", colour="yellow") +   scale_size_manual(values = c(1:3) )   drawplot(data = mtcars, aes(x = wt, y=mpg, size=as.factor(gear)))  

enter image description here

i don't know if there's way set line , point sizes in 2 separate aesthetic mappings, since they're both keyed same aesthetic. here's quick hack might @ least started in direction want go:

gear has 3 levels. so, in call geom_point add 3 value of gear before turning factor. adds 3 new levels gear in plot, total of 6 levels. first 3 levels apply lines, , next 3 levels apply points. can set sizes independently in call scale_size_manual. (that messes legend, i'm not sure how deal without resorting lower-level grid functions.)

drawplot2 <- function(...) ggplot2::ggplot(...) +    stat_summary(fun.y=mean, geom="line", aes(size=factor(gear)), colour="grey40") +    stat_summary(fun.y=mean, geom="point", aes(size=factor(gear + 3)),                 pch=21, fill="yellow", colour="black") +   scale_size_manual(values = c(1,1.5,2,2,3,4))   drawplot2(data = mtcars, aes(x = wt, y=mpg)) 

enter image description here


Comments