我正在尝试调整我的Rmarkdown文档中的饼图,以使其跨越页面的宽度,或者至少变得足够宽以适合所有标签。
我已经尝试了所有方法- 用和调整figure.height和figure.width,边距,但是似乎没有任何效果。要么馅饼本身变小,要么标签被切掉。我希望带有清晰可见标签的馅饼尽可能大,但是每次渲染小馅饼和微小标签时。par(mar)par(oma)
是否至少有一种解决方法,以使标签不被切除(或可以与相邻图表重叠)?任何建议,将不胜感激。
```{r, figure.align = "center", figure.height = 10, figure.width = 12}
par(mfrow=c(1,3), cex.axis=1.5, cex.lab=1.5)
par(mar = c(4,2,4,2))
par(oma = c(3, 3, 3, 3))
pie(a, labels = lbls, font = 2, col = c("tomato", "white"), cex=2)
pie(b, lbls2, font = 2, col = c("tomato", "white"), cex=2)
mtext(side=3, text="Plan Breakdown: Top 20% of Users")
pie(c, lbls3, font = 2, col = c("tomato", "white"))
Run Code Online (Sandbox Code Playgroud)
我有一个包含许多列的宽表,我希望能够在 R-markdown 中使用水平滚动条整齐地显示这些列。我已阅读文档并尝试了以下操作
```{css}
pre code, pre, code {
overflow-x: scroll !important;
}
```
Run Code Online (Sandbox Code Playgroud)
以及options(width = 1000)在代码块中设置。这两种方法都失败了。
kable(mat)) 显示彼此堆叠的行名和列名,但我想通过 x-overflow 避免这种情况
任何建议将不胜感激。这是完整的数据集:
> dput(mat)
structure(list(`Jul 2016` = c(0.108624566189299, 1.76516237793691,
0.24654630490587, 0.336005341665282, 1.00201353799076, 1.36940398901225,
3.66411692441857, 0.927558916609414, 0.691046979743987, 0.450146262999624,
0.917686009737563, 0.140224124770612, 0.843074107500625, 1.05518907118113
), `Aug 2016` = c(0.495219146367162, 0.391441250685602, 1.54749462052876,
0.173654376994818, 0.633756110444665, 0.631372984033078, 0.18316258961296,
0.182683125603944, 3.05005361690094, 3.94560365916646, 1.23740167125376,
0.104842279106379, 1.19900375879825, 0.885420372667623), `Sep 2016` = c(0.233641386257531,
0.0033428730592414, 0.750113554504904, 3.29350166751032, 0.321632610633969,
0.147915420588106, 0.588389918208122, 0.448350375518203, 0.11338227847591,
0.183331309817731, 0.503199412953109, 0.171937711299566, 1.95316866590622,
0.104802044216859), `Oct …Run Code Online (Sandbox Code Playgroud) 我有一个自行车轨迹的样本数据集.我的目标是平均计算出访问B站之间的时间.
到目前为止,我已经能够简单地对数据集进行排序:
test[order(test$starttime, decreasing = FALSE),]
Run Code Online (Sandbox Code Playgroud)
并找到的行索引start_station和end_station等于B.
which(test$start_station == 'B')
which(test$end_station == 'B')
Run Code Online (Sandbox Code Playgroud)
接下来的部分是我遇到麻烦的地方.为了计算出失误的时候自行车是在站B之间,我们必须采取的时间difftime(),其中间start_station = "B"(自行车离开)和下一个出现的创纪录的 地方end_station= "B", 即使记录恰好是在同一行中(见第6行).
使用下面的数据集,我们知道自行车在B站之间7:30:00和16:00:00之外花费了510分钟,B站之间和之外30分钟,18:00:00以及18:30:00B站之间19:00:00和22:30:00之外210分钟,平均为250 minutes.
如何使用R在R中重现此输出difftime()?
> test
bikeid start_station starttime end_station endtime
1 1 A 2017-09-25 01:00:00 B 2017-09-25 01:30:00
2 1 B 2017-09-25 07:30:00 C 2017-09-25 08:00:00
3 1 C 2017-09-25 10:00:00 A 2017-09-25 10:30:00 …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建两个单独的 div,一个覆盖屏幕的左半部分,一个覆盖屏幕的右侧。为什么我的代码只创建了一个 div 覆盖页面的左半部分,当我包含float:left和 时float:right?我该如何解决?
#col-1 {
position: fixed;
width: 50%;
float: left;
height: 100%;
background-color: #282828;
z-index: 1010101010
}
#col-2 {
position: fixed;
width: 50%;
float: right;
height: 100%;
background-color: #0080ff;
z-index: 1010101010
}Run Code Online (Sandbox Code Playgroud)
<div id="col-1">
<h1>This is half of a page</h1>
</div>
<div id="col-2">
<h1>This is another half of a page</h1>
</div>Run Code Online (Sandbox Code Playgroud)
由于我不熟悉Shiny,我对自动数据库查询的最佳实践感兴趣.在撰写本文时,有许多不同的来源有不同的信息.
如果我每隔10分钟查询一次我的postgres数据库,如下例所示,我想确保a)在会话退出时关闭连接并且b)由于打开的连接太多而无法连接.我的仪表板将来一次最多可容纳十几个用户.
已经做了一些研究,我相信,最好的办法做到这一点是不是一定要使用游泳池,但使用"每次查询一个连接"的方式闪亮记载这里
使用reactivePoll(),因为我有正确的方法下面来实现查询,将刷新渲染表每10分钟?我将要查询的数据库肯定会在每次调用时返回不同的数据.这是否意味着, checkFunc和valueFunc应该是相同的或者可以checkFunc将其保留为完全空的功能?
library(shiny)
library(DBI)
args <- list(
drv = dbDriver("PostgreSQL"),
dbname = "shinydemo",
host = "shiny-demo.csa7qlmguqrf.us-east-1.rds.amazonaws.com",
username = "guest",
password = "guest"
)
ui <- fluidPage(
textInput("ID", "Enter your ID:", "5"),
tableOutput("tbl"),
numericInput("nrows", "How many cities to show?", 10),
plotOutput("popPlot")
)
server <- function(input, output, session) {
output$tbl <- renderTable({
conn <- do.call(DBI::dbConnect, args)
on.exit(DBI::dbDisconnect(conn))
sql <- "SELECT * FROM City WHERE ID = ?id;"
query <- sqlInterpolate(conn, sql, …Run Code Online (Sandbox Code Playgroud) 以下是调用API时返回的示例输出:
curl "https://mywebsite.com/api/cars.json&page=1" | jq '.'
Run Code Online (Sandbox Code Playgroud)
使用jq,将如何计算数字或记录charge缺少密钥的位置?我知道代码的第一位将包括在内,jq '. | length'但是如何过滤掉包含或不包含某个键值的对象?
如果应用于以下示例,则输出为 1
{
"current_page": 1,
"items": [
{
"id": 1,
"name": "vehicleA",
"state": "available",
"charge": 100
},
{
"id": 2,
"name": "vehicleB",
"state": "available",
},
{
"id": 3,
"name": "vehicleB",
"state": "available",
"charge": 50
}
]
}
Run Code Online (Sandbox Code Playgroud) 我有一个沿 x 轴绘制日期的数据集(请参阅下面的完整数据集):
> head(test)
date variable value
1 2018-01-17 foo 14
2 2018-01-18 foo 18
3 2018-01-19 foo 22
4 2018-01-20 foo 15
5 2018-01-21 foo 32
6 2018-01-22 foo 27
Run Code Online (Sandbox Code Playgroud)
我的目标是在当前仅显示日期的标签下方包含第二行 x 轴标签(带有星期几)。
但是,当我在 ggplot 中包含注释时,这会引发错误。有人可以建议解决方法吗?
ggplot(data=test,
aes(x=date, y=value, colour=variable)) +
geom_line() + geom_text(aes(label=value),hjust=0, vjust=0) +
annotate(geom = "text", x=date, y= -2, label = weekdays(test$date), size = 4, angle = 90)
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing …Run Code Online (Sandbox Code Playgroud) 我的目标是根据时间加入两个数据表,dplyr或者data.table特别是在事件发生之前和之后立即获取记录.
在示例数据中,这种情况下的事件是踏板车行程.以下是四次旅行 - 两次由踏板车1拍摄,两次由踏板车2拍摄.
> testScooter
start end id
1: 2018-01-18 22:19:13 2018-01-18 22:26:31 1
2: 2018-01-18 23:29:22 2018-01-18 23:37:53 1
3: 2018-01-18 00:22:02 2018-01-18 00:29:21 2
4: 2018-01-18 00:37:52 2018-01-18 01:06:53 2
Run Code Online (Sandbox Code Playgroud)
在单独的表中是以几乎相等的间隔隔开的记录.本id的比赛中与车标no时,跳闸正在进行中.
> intervals
id time available charge
1 1 2018-01-18 21:31:07 yes 83
2 1 2018-01-18 21:41:07 yes 83
3 1 2018-01-18 21:51:07 yes 83
4 1 2018-01-18 22:01:07 yes 83
5 1 2018-01-18 22:11:07 yes 83
6 1 …Run Code Online (Sandbox Code Playgroud) 我有一个表t,其中 x 和 y 值在 x(value列)的每 10 个整数之间间隔开,例如:
value -20 -10 0 24 40 55
1 100 41700 41700 41700 41700 41800 41700
2 90 40200 40600 40700 40800 40800 40800
3 80 39200 39700 39800 40000 40000 39900
4 70 38200 38800 38800 39000 39100 39000
5 60 37200 37800 37900 38000 38200 38200
6 50 36200 36700 36900 37000 37000 37000
7 40 35400 35900 36200 36300 36300 36400
8 30 34600 35300 35600 …Run Code Online (Sandbox Code Playgroud) 我已经生成了一系列小时时间戳:
intervals <- seq(as.POSIXct("2018-01-20 00:00:00", tz = 'America/Los_Angeles'), as.POSIXct("2018-01-20 03:00:00", tz = 'America/Los_Angeles'), by="hour")
> intervals
[1] "2018-01-20 00:00:00 PST" "2018-01-20 01:00:00 PST" "2018-01-20 02:00:00 PST"
[4] "2018-01-20 03:00:00 PST"
Run Code Online (Sandbox Code Playgroud)
给定具有杂乱且间隔不均匀的时间戳的数据集,如何将该数据集中的时间值与最接近的每小时时间戳匹配id,并删除其间的其他时间戳?例如:
> test
time id amount
312 2018-01-20 00:02:14 PST 1 54.9508346
8652 2018-01-20 00:54:41 PST 2 30.5557992
13809 2018-01-20 01:19:27 PST 3 90.5459248
586 2018-01-20 00:03:35 PST 1 79.7635973
9077 2018-01-20 00:56:37 PST 2 75.5356406
21546 2018-01-20 02:25:05 PST 3 36.6017705
7275 2018-01-20 00:47:45 PST 1 12.7618139 …Run Code Online (Sandbox Code Playgroud) r ×8
data.table ×4
dplyr ×4
r-markdown ×2
bash ×1
count ×1
css ×1
css-float ×1
css-position ×1
figure ×1
ggplot2 ×1
html ×1
jq ×1
json ×1
knitr ×1
lubridate ×1
missing-data ×1
pie-chart ×1
shiny ×1
shiny-server ×1