Note that there are some explanatory texts on larger screens.

plurals
  1. POggplot2: Adjust the symbol size in legends
    primarykey
    data
    text
    <p>How should I change the size of symbols in legends? I checked the document of <code>theme</code> but found no answer. </p> <p>Here is an example:</p> <pre><code>library(ggplot2);library(grid) set.seed(1000) x &lt;- 1:6 mu &lt;- sin(x) observed &lt;- mu + rnorm(length(x), 0, 0.5*sd(mu)) data &lt;- data.frame( t=rep(x, 2), value=c(mu, observed) - min(mu, observed) + 0.5, class = rep(c("mu", "observed"), each=length(x))) mu &lt;- data$value[1:length(x)] observed &lt;- data$value[1:length(x) + length(x)] mu.min &lt;- mu - 3 * 0.5 * sd(mu) mu.max &lt;- mu + 3 * 0.5 * sd(mu) g &lt;- ggplot(data=data) g &lt;- g + geom_point(aes(x=value, y=t, shape=class, size=24)) + scale_size(guide="none") g &lt;- g + scale_shape(name="", labels=expression(paste(S[u](t), ", the observation at time ", t), paste(mu[u](t), ", the mean of ", tilde(S)[u](t), " "))) stat_function.color &lt;- gray(0.5) g &lt;- g + geom_segment(aes(y=1:6, yend=1:6, x=mu.min, xend=mu.max, linetype="2", alpha = 1), color=stat_function.color) + scale_alpha(guide="none") + scale_linetype(name= "", labels=expression(paste("probability density function (pdf) of ", tilde(S)[u], " at time ", t))) for(i in 1:length(x)) { g &lt;- g + stat_function(fun=function(x, i) { ifelse( x &lt;= mu.max[i] &amp; x &gt;= mu.min[i], dnorm(x, mu[i], sd(mu)) + i, NA) }, color=stat_function.color, args=list(i=i)) } background.color &lt;- gray(0.75) g &lt;- g + theme( axis.text=element_blank(), title=element_text(size=rel(1.5)), legend.text=element_text(size=rel(1.5)), legend.position="top", legend.direction="vertical", # legend.key.size = unit(2, "cm"), panel.background=element_rect(fill=background.color), panel.grid.major=element_line(color=background.color), panel.grid.minor=element_line(color=background.color) ) + coord_flip() plot(g) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload