tags:

views:

237

answers:

2

I have a data frame showing four classes for each year, along with their respective shares of the total for 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 with no fill specified, I get a uniform gray box, as expected.

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

So I try to add fill=class, and it doesn't 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 to the class factor to get it working properly with scale_fill_brewer()? The idea, obviously, is to shade each area of the graph according to its class.

Thanks.

A: 

The problem was in some theme parameters I'd set, so it went away once I started building a runnable example to reproduce here. Thanks for the help.

MW Frost
A: 

I just had this problem. It seams that

theme_set(theme_bw(base_size=9))

results in the error reported. But

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

works.

I googled and found the example at the learnr blog

I dont know what the first example does not work though?

Andreas