- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个投影仪演示文稿,其中我有一个图形显示几个时间序列和一个图例(比如 10 个国家/地区的 10 个系列)。我想知道是否有一种相当简单的方法可以在 beamer 中动态添加系列,大概是通过让一个块创建 10 个图形并将它们作为单独的帧按顺序插入。随着更多系列的添加,图例也将更新。我猜测解决方案将涉及循环遍历 10 个国家/地区的列表,一次依次添加一个国家/地区。
下面是一个合理最小化的示例,其中一个图形显示了所有系列。我保留了原始数据,所以代码有点长,我希望不会有问题。 [由于某种原因,图引用号没有显示,所以如果有人知道如何解决这个问题,我将相应地更新代码。]
\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
<<setup, include=FALSE>>=
library(knitr)
### Load Libraries:
library(ggplot2)
library(scales)
library(xlsx)
library(reshape2)
library(RColorBrewer)
### Set Color & Shape Scheme:
colorPalette <- colorRampPalette(brewer.pal(9, "Set1"))(9)
shapePalette <- c(17, 2, 16, 1, 15, 0, 18, 5, 24)
### Load Data
df <-
structure(list(Year = c(1970, 1971, 1972, 1973, 1974, 1975, 1976,
1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987,
1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2010), US = c(3.42265371889757, 3.40883775035394, 3.48714154544623,
3.3918808399871, 3.2149786413858, 3.19962742859596, 3.26773941561925,
3.25691041518237, 3.21869258301295, 3.32930306011566, 3.54928091846329,
3.50605987885847, 3.58930933604703, 3.56947109521563, 3.39111206142848,
3.45519673484759, 3.63509892164379, 3.66190461652477, 3.62269304628001,
3.72937652705034, 3.72194002526906, 3.77418488930653, 3.78624707450568,
3.80047546800654, 3.71653349394787, 3.77606897480101, 3.88548730017041,
4.00931412858258, 4.23951158932882, 4.52108993780641, 4.50347585611652,
4.36449734409992, 4.1682991648011, 4.21151821995036, 4.47120525351423,
4.69843213308901, 4.87750093832889, 4.94023200000774, 4.36016047791801,
4.0607640596732, 4.09921895393402), Japan = c(2.9862145656143,
3.27993801479434, 3.73480428038432, 4.03650790453792, 3.96024700378101,
3.85535193733559, 3.74753619228984, 3.73415315599982, 3.78128411166629,
4.05653721191352, 4.33699408182422, 4.57194662728378, 4.74070126950775,
4.88225942346334, 4.85668276127374, 4.86434213335031, 5.29783056182241,
6.106326266624, 6.55780181703131, 6.92283014250265, 6.98525270056026,
6.61443218992994, 6.26683743354421, 6.09780509506938, 6.09430602943074,
6.0205640302122, 5.85719231863445, 5.76982637280404, 5.92011081443946,
6.01862462053832, 5.96279852951204, 5.89669397027792, 5.83636511534043,
5.80547391655667, 5.7075874671511, 5.73828029065974, 5.83468446323163,
5.78506098967758, 5.86809206830935, 6.19089593818452, 6.01237485111239
), Germany = c(2.25028311964994, 2.19997368560301, 2.2178393884591,
2.18479912165755, 2.20126698092742, 2.29465431841867, 2.28676888070146,
2.36449969898551, 2.45751763593208, 2.48603507321817, 2.5296440222246,
2.62013228686627, 2.72744244161062, 2.79661246602516, 2.83672792160897,
2.90342841424184, 2.94643285549051, 3.04244965338094, 3.03297460198842,
3.01193899964686, 2.93337465632571, 2.86881455730272, 2.89751818871317,
3.03685599967001, 3.07172228372608, 3.10277372448817, 3.20750040783546,
3.31142434149651, 3.4068805122629, 3.50800500275626, 3.56473937826538,
3.58484961640301, 3.63016879171539, 3.70546508418438, 3.7228401653644,
3.83695092187362, 3.77789847916255, 3.79048630783758, 3.89654156987207,
4.15195285079167, 4.11719616413334), France = c(3.10041308276844,
3.03528473434106, 3.07224268696263, 3.04564643242234, 3.03367305451033,
3.17046521393278, 3.14669782623641, 3.16669403005716, 3.18863871842954,
3.18896735512728, 3.2118056113271, 3.20743980770504, 3.12834755391509,
3.14710682768189, 3.15601383211585, 3.13941624302193, 3.17643343055692,
3.24983758397325, 3.25067186123412, 3.37771667047246, 3.43020728196131,
3.41686030175874, 3.37001936959952, 3.42404696480599, 3.39182912196306,
3.33351776785474, 3.36339959767104, 3.40141917545778, 3.41654272775737,
3.59046779724721, 3.75667824174458, 3.8453884378285, 3.99389592998013,
4.23586045226769, 4.56786143701458, 4.99891524426584, 5.33816941234829,
5.53459881682856, 5.52546980231239, 5.62610051047266, 5.74557817379884
), UK = c(3.05606066084056, 3.28136211640651, 3.53517285720912,
3.4015466274181, 3.37355298562955, 3.01189577998554, 2.82778300365569,
2.84264285305362, 2.98206660971185, 3.12871440091241, 3.09138672763463,
3.09848424547132, 3.14369391882952, 3.22093566060216, 3.32453649939209,
3.38203640523729, 3.60975706832705, 3.79175820721175, 4.01996620376656,
4.35222485547853, 4.29074956516369, 4.17858265550709, 4.10601829597889,
4.20374199691601, 4.11508157027746, 4.03388870700175, 4.10429676406955,
4.31554950891114, 4.5334498290607, 4.93968597303074, 5.14555007361808,
4.93640691154845, 4.65854702485502, 4.64802186851695, 4.81195849182541,
4.99214720462646, 5.18939866500773, 5.22710830625107, 4.90522205950409,
5.04405276332021, 5.21876019202926), Italy = c(2.39215637647118,
2.44845609346066, 2.57763397859687, 2.5316735314333, 2.81963001666614,
3.20731869907343, 3.04031888674008, 2.99802984507696, 2.9399636053426,
2.98448248214816, 3.21914189644141, 3.6486889809305, 3.82528788673797,
3.7839347408454, 3.68725754425826, 3.63013782782453, 3.71188604347889,
3.72564825455312, 3.69103408796593, 4.01046564977317, 4.48058507188833,
4.85343617432174, 5.34193146606732, 5.75157758748574, 5.55896964791881,
5.18387020411741, 5.13555481434592, 5.2948199364687, 5.50848886386976,
5.61393915207144, 5.63190988601601, 5.61666627489398, 5.69557515734195,
5.88376044815484, 5.99564177268367, 6.2362241942999, 6.37208451589795,
6.42483181625212, 6.60711186696451, 6.90849908711598, 6.76471157203947
), Canada = c(2.46999246515975, 2.51899440684339, 2.51072441779505,
2.46367577973226, 2.38599551549661, 2.41613850112873, 2.35867265240764,
2.43115439201043, 2.50563564378943, 2.54935677726461, 2.64401591844765,
2.61476256582721, 2.72962132388488, 2.76836750499094, 2.76034296473846,
2.74156887850989, 2.84357489511072, 2.82102192429222, 2.7618487567955,
2.83942901661988, 2.94356263791855, 3.07986195414658, 3.25522196117649,
3.40971743227054, 3.47667187371024, 3.46293485753507, 3.62994233169318,
3.73637768424018, 3.80416175315756, 3.77481010019493, 3.65484296538209,
3.68033672114661, 3.57770233271274, 3.55367989746207, 3.59965457056012,
3.72599178459817, 3.88252681901122, 4.01544408308135, 3.82752126884386,
4.12591287289822, 4.16188986951361), Australia = c(3.29797647418749,
3.38491225540234, 3.44029047212715, 3.47125566425928, 3.4810218921083,
3.48844677886234, 3.45360682034598, 3.41383660897562, 3.48141675382338,
3.36482181389334, 3.37038861174626, 3.45350624176025, 3.46800728369306,
3.51340651593045, 3.45348452180453, 3.49922503882649, 3.49995742217246,
3.50727511525372, 3.55283382684878, 3.75439065549366, 3.86282026029909,
4.00909028345048, 4.09888554022219, 4.03008779282658, 4.0786015030136,
4.1171195564421, 4.00527485567151, 4.06619881966008, 4.17322264837539,
4.2885540538951, 4.42376485715699, 4.53847634962058, 4.63205164187482,
4.8161720868947, 5.00224755604537, 5.21903971255623, 5.3206272356995,
5.55203639942649, 5.43848775952897, 5.03805394614743, 5.17911849231265
), Spain = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 3.61582686985211, 3.85335841950962, 4.15596177940659,
4.34864142485489, 4.57079367080665, 4.52903738374002, 4.43043021221076,
4.43875554480713, 4.29525396408518, 4.32973357345343, 4.32844261880396,
4.42181465426299, 4.62656574873193, 4.78983037420811, 5.06749639036482,
5.458653674397, 5.98283114191667, 6.65596447354794, 7.24210561415232,
7.68573552177333, 7.92455000411218, 7.86235658455681, 7.8884251146486,
7.55209874234684)), .Names = c("Year", "US", "Japan", "Germany",
"France", "UK", "Italy", "Canada", "Australia", "Spain"), row.names = c(NA,
-41L), class = "data.frame")
df <- melt(df, id.var = "Year")
names(df) <- c("Year","Country", "Percent")
@
\begin{document}
\title{Beamer `Overlay' with \texttt{knitr}}
\subtitle{1. Code overlays for each country data \\
2. Fix Figure reference not displaying}
\author{PatrickT based on Piketty}
\date{}
\maketitle
\begin{frame}[fragile]% need [fragile] option
\frametitle{Plot}
<<Figure1, fig.cap = '[Figure 5.3] http://piketty.pse.ens.fr/fr/capital21c', fig.height=4, fig.width=6, out.width='1\\maxwidth', dev='pdf', fig.align='center', cache=TRUE, warning=FALSE, echo=FALSE>>=
(p1 <- ggplot(data = df, aes(x = Year, y = Percent, group = Country, shape = Country, colour = Country)) + geom_line() + geom_point(aes(shape = Country, colour = Country), size = 3) + ylab("Value of private capital (% national income)") + xlab("") + theme_bw() + scale_y_continuous(labels = percent, breaks = pretty_breaks(n = 6)) + scale_x_continuous(breaks = seq(1970, 2010, by = 5)) + scale_shape_manual(name = "Country", values = shapePalette[1:9]) + scale_colour_manual(name = "Country", values = colorPalette[1:9]) + theme(legend.key = element_blank(), legend.position = c(.2, .75), legend.background = element_rect(colour = 'black')) + guides(shape = guide_legend(ncol = 2)))
@
\end{frame}
\end{document}
最佳答案
我使用 rCharts
制作了一个动态图和 nPlot
,基于 nvd3/d3
图书馆。不是我正在寻找的 beamer/pdf 方法,但满足我的目的:
```{r 'Figure_5_3_rCharts', message = FALSE, warning = FALSE, error = FALSE, echo = FALSE, tidy = FALSE, cache = FALSE}
require(rCharts)
load("../../data/df_5_3.Rda")
# round data for rChart tooltip display
df_5_3$value <- round(df_5_3$value, 3)
n <- nPlot(data = df_5_3, value ~ Year, group = 'variable', color = 'variable', shape = 'variable', type = 'lineChart')
n$chart(forceY = c(2, 7))
n$yAxis(axisLabel = 'Value of private capital (% national income)')
n$chart(margin = list(left = 80))
n$yAxis(tickFormat = "#! function(d) {return Math.round(d*100*100)/100 + '%'} !#")
n$xAxis(axisLabel = 'Year')
n$chart(useInteractiveGuideline = TRUE)
n$chart(color = colorPalette)
n$addParams(height = 500, width = 800)
n$setTemplate(afterScript = '<style>
.nv-point {
stroke-opacity: 1!important;
stroke-width: 5px!important;
fill-opacity: 1!important;
}
</style>')
n$save('figures/Figure_5_3.html', standalone = TRUE)
```
<iframe src = 'figures/Figure_5_3.html' alt = "Figure 5.3. Private capital in rich countries, 1970-2010.">
</iframe><icaption class = 'icaption'>Figure 5.3. Private capital is worth between 2 and 3.5 years of national income in rich countries in 1970, and between 4 and 7 years of national income in 2010.</icaption>
<footer class = 'footnote'>
Concept and data: Thomas Piketty. Chart created with ``rCharts`` (author: Ramnath Vaidyanathan)
</footer>
icaption
和
footer
如果有人觉得它有用。这是一个屏幕截图:
关于r - 针织和 Beamer 与图中的叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27343713/
我想做的是让 JTextPane 在 JPanel 中占用尽可能多的空间。对于我使用的 UpdateInfoPanel: public class UpdateInfoPanel extends JP
我在 JPanel 中有一个 JTextArea,我想将其与 JScrollPane 一起使用。我正在使用 GridBagLayout。当我运行它时,框架似乎为 JScrollPane 腾出了空间,但
我想在 xcode 中实现以下功能。 我有一个 View Controller 。在这个 UIViewController 中,我有一个 UITabBar。它们下面是一个 UIView。将 UITab
有谁知道Firebird 2.5有没有类似于SQL中“STUFF”函数的功能? 我有一个包含父用户记录的表,另一个表包含与父相关的子用户记录。我希望能够提取用户拥有的“ROLES”的逗号分隔字符串,而
我想使用 JSON 作为 mirth channel 的输入和输出,例如详细信息保存在数据库中或创建 HL7 消息。 简而言之,输入为 JSON 解析它并输出为任何格式。 最佳答案 var objec
通常我会使用 R 并执行 merge.by,但这个文件似乎太大了,部门中的任何一台计算机都无法处理它! (任何从事遗传学工作的人的附加信息)本质上,插补似乎删除了 snp ID 的 rs 数字,我只剩
我有一个以前可能被问过的问题,但我很难找到正确的描述。我希望有人能帮助我。 在下面的代码中,我设置了varprice,我想添加javascript变量accu_id以通过rails在我的数据库中查找记
我有一个简单的 SVG 文件,在 Firefox 中可以正常查看 - 它的一些包装文本使用 foreignObject 包含一些 HTML - 文本包装在 div 中:
所以我正在为学校编写一个 Ruby 程序,如果某个值是 1 或 3,则将 bool 值更改为 true,如果是 0 或 2,则更改为 false。由于我有 Java 背景,所以我认为这段代码应该有效:
我做了什么: 我在这些账户之间创建了 VPC 对等连接 互联网网关也连接到每个 VPC 还配置了路由表(以允许来自双方的流量) 情况1: 当这两个 VPC 在同一个账户中时,我成功测试了从另一个 La
我有一个名为 contacts 的表: user_id contact_id 10294 10295 10294 10293 10293 10294 102
我正在使用 Magento 中的新模板。为避免重复代码,我想为每个产品预览使用相同的子模板。 特别是我做了这样一个展示: $products = Mage::getModel('catalog/pro
“for”是否总是检查协议(protocol)中定义的每个函数中第一个参数的类型? 编辑(改写): 当协议(protocol)方法只有一个参数时,根据该单个参数的类型(直接或任意)找到实现。当协议(p
我想从我的 PHP 代码中调用 JavaScript 函数。我通过使用以下方法实现了这一点: echo ' drawChart($id); '; 这工作正常,但我想从我的 PHP 代码中获取数据,我使
这个问题已经有答案了: Event binding on dynamically created elements? (23 个回答) 已关闭 5 年前。 我有一个动态表单,我想在其中附加一些其他 h
我正在尝试找到一种解决方案,以在 componentDidMount 中的映射项上使用 setState。 我正在使用 GraphQL连同 Gatsby返回许多 data 项目,但要求在特定的 pat
我在 ScrollView 中有一个 View 。只要用户按住该 View ,我想每 80 毫秒调用一次方法。这是我已经实现的: final Runnable vibrate = new Runnab
我用 jni 开发了一个 android 应用程序。我在 GetStringUTFChars 的 dvmDecodeIndirectRef 中得到了一个 dvmabort。我只中止了一次。 为什么会这
当我到达我的 Activity 时,我调用 FragmentPagerAdapter 来处理我的不同选项卡。在我的一个选项卡中,我想显示一个 RecyclerView,但他从未出现过,有了断点,我看到
当我按下 Activity 中的按钮时,会弹出一个 DialogFragment。在对话框 fragment 中,有一个看起来像普通 ListView 的 RecyclerView。 我想要的行为是当
我是一名优秀的程序员,十分优秀!