Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How to add the legend to combo plot?

$
0
0

Here is the data set:

d <- tribble(
  ~priceseg,   ~price_n, ~zet_n, ~zet_n2,
     "(0,1]",     16,      2,      24,      
     "(1,3]",     33,      3,      38,
     "(3,5]",     33,      2,      25,
     "(5,6]",     17,      1,      13,
)

And here is the visualisation thanks to @d.b

ggplot(d) +
  geom_col(aes(x = priceseg, y = price_n), fill = ("#F1948A"), colour="black", size = 0.6) +
  geom_line(data = d, mapping = aes(x = priceseg, y = zet_n2, group = 1), colour = "#154360", size = 1) +
  geom_label(data = d, mapping = aes(x = priceseg, y = price_n, label = price_n), nudge_y = -0.6)

Now, I want to add the legend for bar plot and line in the visualisation something like this: Combined line & bar geoms: How to generate proper legend?

Also, I would like to add % in geom_label.

But somehow, I could not manage to implement it. Any help?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>