Ggplot: manually add legends for aesthetics that don't appear

I want to create a barcode superimposed on points where both have separate legends. In addition, I want to select the color of the bars and the size of the dots using the arguments outside aes(). Since both images are not displayed, a legend is not created.

1) How to add a legend manually for filling and size?

library(ggplot2)

d <- data.frame(group = 1:3,    
                prop = 1:3 )

ggplot(d, aes(x=group, y=prop)) +
  geom_bar(stat="identity", fill="red") +
  geom_point(size=5)

Here's what I came up with: I used fictitious comparisons and subsequently changed the legend to suit my needs. But this approach seems awkward to me.

2) Is there a manual way to say: add a legend with this name, these figures, these colors, etc.?

d <- data.frame(dummy1="d1",
                dummy2="d2",
                group = 1:3,    
                prop = 1:3 )


ggplot(d, aes(x=group, y=prop, fill=dummy1, size=dummy2)) +
  geom_bar(stat="identity", fill="red") +
  geom_point(size=5) +
  scale_fill_discrete(name="fill legend", label="fill label") +
  scale_size_discrete(name="size legend", label="size label")

fill dummy1. , scale_fill_discrete . size.

3) , . ?

0
1

, : " , , aes()". , , , , , ggplot?

, <

library(ggplot2)

d <- data.frame(group = 1:3,    
                prop = 1:3 )

ggplot(d, aes(x=group, y=prop)) +
    geom_bar(stat="identity",aes( fill="label")) +
    geom_point(aes(size='labelsize')) +
    scale_fill_manual(breaks = 'label', values = 'red')+
    scale_size_manual(breaks = 'labelsize', values = 5)
+3

Source: https://habr.com/ru/post/1693827/


All Articles