title: How to change the orientation of the "Key" of a Legend in ggplot?
body: <p>How can I change the key of the caption below so that it is in the horizontal position without changing the vertical lines of the graph.</p>
  
  <pre><code>set.seed(000)
  m &lt;- matrix(rnorm(100,0,1),100,1)
  dt &lt;- data.frame(m)
  names(dt) &lt;- c("X")
  
  library(ggplot2)
  
  g2 &lt;- ggplot(dt, aes(x=X)) 
  g2 &lt;- g2+geom_histogram(aes(y=..density..),      # Histogram with density instead of count on y-axis
                          binwidth=.5,
                          colour="black", fill="white",breaks=seq(-2, 2, by = 0.1)) 
  g2 &lt;- g2+geom_density(alpha=.3, fill="#cccccc") # Overlay with transparent density plot
  g2 &lt;- g2+  geom_vline(aes(xintercept=0, linetype="Valor Verdadeiro"),show.legend =TRUE)
  g2 &lt;- g2+  geom_vline(aes(xintercept=mean(dt$X, na.rm=T),    linetype="Valor Estimado"),show.legend =TRUE)
  g2 &lt;- g2+  scale_linetype_manual(values=c("dotdash","solid")) # Overlay with transparent density plot
  g2 &lt;- g2+  xlab(expression(paste(gamma[1])))+ylab("Densidade")
  g2 &lt;- g2+  theme(legend.key.height = unit(2, "cm") ,
                   legend.position = c(0.95, 0.95),
                   legend.justification = c("right", "top"),
                   legend.box.just = "right",
                   legend.margin = margin(6, 6, 6, 6),
                   legend.title=element_blank(),
                   legend.direction = "vertical",
                   legend.background = element_rect(fill="gray", size=.5, linetype="dotted"))
  g2 &lt;- g2+ guides(linetype = guide_legend(override.aes = list(size = 1)))
  g2
  </code></pre>
  
  <p>Note: I want to rotate the line from within the caption that is in <code>dotdash</code> and <code>solid</code> format.</p>
  
  <p><a href="https://i.stack.imgur.com/9C7zL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9C7zL.jpg" alt="enter image description here"></a></p>