Ggplot2: using geom_area () function

I have a data frame showing four classes for each year, as well as their respective shares for just that year.

> head(df) class year share 1 class1 1975 0.806 2 class2 1975 0.131 3 class3 1975 0.018 4 class4 1975 0.045 5 class1 1976 0.788 6 class2 1976 0.151 

When I run ggplot without specifying fill , I get a single gray square, as expected.

 > ggplot(df, aes(x=year, y=share, group=class)) + geom_area() + scale_fill_brewer() 

So, I am trying to add fill=class and it does not work.

 > ggplot(df, aes(x=year, y=share, group=class, fill=class)) + geom_area() + scale_fill_brewer() Error in inherits(x, "factor") : object "base_size" not found In addition: Warning message: In inherits(x, "factor") : restarting interrupted promise evaluation > 

What can I do with class coefficient so that it works fine with scale_fill_brewer() ? Obviously, the idea is to shade every area of โ€‹โ€‹the graph according to its class.

Thanks.

+1
source share
2 answers

I had this problem. These are the seams that

 theme_set(theme_bw(base_size=9)) 

results in an error message. But

 base_size <- 9 theme_set(theme_bw(base_size=base_size)) 

work.

I googled and found an example in learnr blog

I do not know that the first example does not work though?

+1
source

The problem was some of the theme options that I installed, so it was gone when I started creating a reproducible example for playback here. Thanks for the help.

0
source

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


All Articles