- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试关注 this ggplot2 教程(不幸的是它没有评论来问我的问题)面积图,但由于某种原因我的输出与作者的输出不同。我执行以下代码:
library(ggplot2)
charts.data <- read.csv("copper-data-for-tutorial.csv")
p1 <- ggplot() + geom_area(aes(y = export, x = year, fill = product), data = charts.data, stat="identity")
dataset是以下内容:
> charts.data
product year export percentage sum
1 copper 2006 4176 79 5255
2 copper 2007 8560 81 10505
3 copper 2008 6473 76 8519
4 copper 2009 10465 80 13027
5 copper 2010 14977 86 17325
6 copper 2011 15421 83 18629
7 copper 2012 14805 82 18079
8 copper 2013 15183 80 19088
9 copper 2014 14012 76 18437
10 others 2006 1079 21 5255
11 others 2007 1945 19 10505
12 others 2008 2046 24 8519
13 others 2009 2562 20 13027
14 others 2010 2348 14 17325
15 others 2011 3208 17 18629
16 others 2012 3274 18 18079
17 others 2013 3905 20 19088
18 others 2014 4425 24 18437
当我打印绘图时,我的结果是:
相反,教程中完全相同的代码显示了一个顺序相反的图,看起来好多了,因为底部的数量越少:
我怀疑作者省略了一些代码,或者输出不同,因为我们使用了不同的 ggplot2 版本。如何更改堆叠顺序以获得相同的输出?
我的 sessionInfo()
是
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] plyr_1.8.4 extrafont_0.17 ggthemes_3.3.0 ggplot2_2.2.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.8 digest_0.6.10 assertthat_0.1 grid_3.3.2 Rttf2pt1_1.3.4 gtable_0.2.0 scales_0.4.1
[8] lazyeval_0.2.0 extrafontdb_1.0 labeling_0.3 tools_3.3.2 munsell_0.4.3 colorspace_1.3-1 tibble_1.2
最佳答案
这里有两个选项,都需要您的 aes(fill)
成为factor
.
1) 更改 factor
的顺序所以所需的添加剂level
首先是:
df$product %<>% factor(levels= c("others","copper"))
ggplot(data = df, aes(x = year, y = export)) +
geom_area(aes(fill = product), position = "stack")
2) 或保持原样(铜优先)并告诉 position_stack(reverse = TRUE)
:
df$product %<>% as.factor()
ggplot(data = df, aes(x = year, y = export)) +
geom_area(aes(fill = product), position = position_stack(reverse = T))
%<>%
来自library(magrittr)
关于ggplot2 geom_order中的反向堆叠顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40986648/
我能否获得一个具有两个参数的递归Prolog谓词,称为反向,它返回列表的反向: 示例查询和预期结果: α-反向([a,b,c],L)。 L = [c,b,a]。 由两个称为palindrome的参数组
在使用 get_dummies() 将分类数据转换为数字数据后,我的数据框看起来像这样 score1 score2 country_CN country _AU category_leader ca
我有一张 table ,上面有一个国家/地区列表。说这些国家之一是“马其顿” 如果搜索“马其顿共和国”,什么 SQL 查询会返回“马其顿”记录? 我相信在 linq 中它会是这样的 var count
我们有一个角色继承结构,它假设每个人都默认获得最低级别的角色,而不是最高级别的过滤,如下图所示: role.Everyone //lowest level; everyone gets this ro
我正在使用 $.each() 解析数组,但在其中,我使用 .splice() 方法,因此我需要向后迭代。这可能吗? var store = [...]; //... var rules = [...]
我有一个 SPLObjectStorage 对象,其中 Player 对象作为键,分数作为与之关联的信息。玩家对象按照从最高分到最低分的顺序添加到存储中,但我现在需要以相反的顺序遍历它们。 我还需要能
我无法理解这一点:如果我给 Prolog reverse([], A). 它工作得很好,如果我给它 reverse(A, [] ). 并根据第一个建议回答 ; 它挂起!为什么? (GNU Prolog
我有一个 SPLObjectStorage 对象,其中 Player 对象作为键,分数作为与之关联的信息。玩家对象按照从最高分到最低分的顺序添加到存储中,但我现在需要以相反的顺序遍历它们。 我还需要能
我有一个HashMap看起来像: HashMap playerHashMap = new HashMap<>(); 玩家是包含姓名、号码、年龄等的对象。 现在我已经对它进行了排序,它看起来像这样: k
我有这个: file://localhost/Volumes/Untitled%20RAID%20Set%201/Callum/iTunes/Music/Steppenwolf/Steppenwolf
我正在使用 std::regex 并希望找到与某个用户定义的正则表达式字符串匹配的字符串中的最后一个位置。 例如,给定正则表达式 :.* 和字符串“test:55:last”,我想找到“:last”,
有一个表 ServErog(服务),它被重新引导到 4 个表 ServA、ServB、ServC、ServD(它们是不同的非统一服务),其中包含 servtype(服务类型)和 type_id(来自其
这个问题在这里已经有了答案: What is the best way to convert date from JavaScript string in format YYYYMMDD to Ja
我知道如何获得包含几个词的所有结果: SELECT * FROM `table` WHERE MATCH (`row`) AGAINST ('+word1 +word2' IN BOOLEAN MOD
你好,我有这个 html 代码: .container{ width: 450; height: 400; border:1px solid
我想知道是否有任何方法可以使用相同的 CSS 过渡实例来将其向前移动然后向后/向后移动。例如,假设我有这种转变: @-webkit-keyframes fade-transition { fr
假设我有这些字符串: char ref[30] = "1234567891234567891"; char oth[30] = "1234567891234567891"; 我想在 C++ 中使用 S
所以我有这段代码,它使 xcode 崩溃 void strrev(const std::string& str) { for(size_t i=str.length();i>=0;i--)
我正在使用下面的代码使每张图片 1 对 1 淡入淡出。我怎样才能反向执行此操作以使图片以相反的顺序加载? img {display:none;} $('img').each(function(
我正在尝试弄清楚如何改变 FrameLayout 堆叠其子项的方式。 目前它是最新的(先进先出)。我想更改它,使最新的 child 位于底部(FILO)。我试着查看 FrameLayout 的源代码,
我是一名优秀的程序员,十分优秀!