ggplot2:使用geom_area()函数 [英] ggplot2: using the geom_area() function
问题描述
我有一个数据框,显示每年有四个班级,以及他们各自在那一年的份额。
> (df)
班级年份
1班1 1975 0.806
2班2 1975 0.131
3班3 1975 0.018
4班4 1975 0.045
5班1 1976 0.788
6 class2 1976 0.151
当我运行 ggplot
没有
fill 指定,我得到了一个统一的灰色框,正如预期的那样。
> ggplot(df,aes(x = year,y = share,group = class))+ geom_area()+ scale_fill_brewer()
所以我尝试添加 fill = class
,它不起作用。
> ggplot(df,aes(x = year,y = share,group = class,fill = class))+ geom_area()+ scale_fill_brewer()
$ b $继承中的错误(x,factor):对象base_size未找到
此外:警告消息:
继承(x,factor):重新启动中断诺言评估
>
我可以对类
因子做些什么使用 scale_fill_brewer()
来正常工作?这个想法显然是根据它的类来遮蔽图的每个区域。
谢谢。
我刚刚遇到了这个问题。它接吻了
theme_set(theme_bw(base_size = 9))
会导致报告的错误。但是
base_size< - 9
theme_set(theme_bw(base_size = base_size))
正常工作。
我搜索了一下学习者博客
我不知道第一个例子不起作用吗?
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.
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?
这篇关于ggplot2:使用geom_area()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!