我想知道正确的方式来增加排边框 造型和斑马条纹 选项,以数据表与包创建DT的R.
简单的启动示例:
library(DT)
datatable(iris)
Run Code Online (Sandbox Code Playgroud)
选项的简单示例:
datatable(head(iris, 20), options = list(
columnDefs = list(list(className = 'dt-center', targets = 4)),
pageLength = 5,
lengthMenu = c(5, 10, 15, 20)
))
Run Code Online (Sandbox Code Playgroud)
不知道我为什么收到投票?如果有任何不清楚或如何改善这个问题,请告诉我.
有没有办法让ggplot2的geom_density()函数模仿ggvis的行为layer_densities()?也就是说,在没有调用的情况下使它p1看起来如此p3(见下文)xlim()?具体来说,我更喜欢使密度曲线的尾部平滑的视图.
library(ggvis)
library(ggplot2)
faithful %>%
ggvis(~waiting) %>%
layer_densities(fill := "green") -> p1
ggplot(faithful, aes(x = waiting)) +
geom_density(fill = "green", alpha = 0.2) -> p2
ggplot(faithful, aes(x = waiting)) +
geom_density(fill = "green", alpha = 0.2) +
xlim(c(30, 110)) -> p3
p1
p2
p3
Run Code Online (Sandbox Code Playgroud)
ggvis输出:

ggplot2"默认":

ggplot2"需要":

注意:可以通过以下(使用trim=TRUE)制作ggvis mimic ggplot2 ,但我想转向另一个方向......
faithful %>%
compute_density(~waiting, trim=TRUE) %>%
ggvis(~pred_, ~resp_) %>%
layer_lines()
Run Code Online (Sandbox Code Playgroud) 我有按国家/年组织的数据,其中包含二元关系的ID.我想通过二年级组织这个.
以下是我的数据组织方式:
dyadic_id country_codes year
1 1 200 1990
2 1 20 1990
3 1 200 1991
4 1 20 1991
5 2 300 1990
6 2 10 1990
7 3 100 1990
8 3 10 1990
9 4 500 1991
10 4 200 1991
Run Code Online (Sandbox Code Playgroud)
以下是我希望如何组织数据:
dyadic_id_want country_codes_1 country_codes_2 year_want
1 1 200 20 1990
2 1 200 20 1991
3 2 300 10 1990
4 3 100 10 1990
5 4 500 200 1991
Run Code Online (Sandbox Code Playgroud)
这是可重现的代码:
dyadic_id<-c(1,1,1,1,2,2,3,3,4,4)
country_codes<-c(200,20,200,20,300,10,100,10,500,200)
year<-c(1990,1990,1991,1991,1990,1990,1990,1990,1991,1991)
mydf<-as.data.frame(cbind(dyadic_id,country_codes,year)) …Run Code Online (Sandbox Code Playgroud) 鉴于此data.frame:
# x y
# 1 a b,c,d
# 2 c b,c,d
# 3 c b,c,d
# 4 a e,f,g
# 5 a b,c,d
# 6 c a,b,c
# 7 b b,c,d
# 8 c <NA>
# 9 c e,f,g
# 10 a <NA>
Run Code Online (Sandbox Code Playgroud)
我想要的输出是:
# x y pos contains
# 1 a b,c,d NA FALSE
# 2 c b,c,d 2 TRUE
# 3 c b,c,d 2 TRUE
# 4 a e,f,g NA FALSE
# 5 a b,c,d …Run Code Online (Sandbox Code Playgroud) 考虑以下:
library(ggplot2)
ggplot(mtcars, aes(disp, mpg)) +
geom_point(aes(color = factor(cyl))) +
geom_smooth(aes(color = factor(cyl)), se = FALSE, method = "lm") +
geom_smooth(se = FALSE, method = "lm", fullrange = TRUE, color = "black")
Run Code Online (Sandbox Code Playgroud)
是否可以为黑线添加比例或图例?就像是:
说我有一个shiny::sliderInput:
...
sliderInput("input_1", "Title_1",
min = 1, max = 10, value = 5)
...
Run Code Online (Sandbox Code Playgroud)
是否可以引用min、max和/或value不同的sliderInput?这样做的用例是使第二个输入依赖于第一个输入。调整第二个输入的最小值的东西永远不会小于来自 的值input_1。
类似的东西(这不起作用):
sliderInput("input_2", "Title_2",
min = input_1$value, max = 10, value = input_1$value)
Run Code Online (Sandbox Code Playgroud)
我的预感是这可能与renderUI,但不确定从哪里或如何开始?
有哪些方法可以转换会话路径数据,例如:
df
# Session Link1 Link2 Link3 Link4 Link5
# 1 1 A B
# 2 2 C
# 3 3 D A B
# 4 4 C F G H J
# 5 5 A B C
Run Code Online (Sandbox Code Playgroud)
进入如下所示的数据集:
desired
# Session From To
# 1 1 A B
# 2 2 C <NA>
# 3 3 D A
# 4 3 A B
# 5 4 C F
# 6 4 F G
# 7 4 G H
# …Run Code Online (Sandbox Code Playgroud) 我有一个数据帧如下:
df = data.frame(a = 1:4, strings = c('ooss_bboo_foo','ee_bbbbee_fffee','aas_baa_ffaa_daa', 'iisss_bbbbii_ffffii_dii_mii'))
Run Code Online (Sandbox Code Playgroud)
我想拆分_,生成新的列(或新的数据框,并不重要).可以用min(lengths(strsplit(df$strings, "_")))和估计出现的次数max(lengths(strsplit(df$strings, "_")))
期望的输出:
X1 X2 X3
1 ooss bboo foo
2 ee bbbbee fffee
3 aas_baa ffaa daa
4 iisss_bbbbii_ffffii dii mii
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多正则表达式,我已经非常绝望了......
考虑这个简单的例子,它从字符串向量中累积单词“This”的出现次数:
library(purrr)
library(stringr)
sentences <- c("This is a sentence.",
"This is another sentence.",
"One more This")
reduce(str_count(sentences, "This"), `+`) # SUCCESS! Returns 3
Run Code Online (Sandbox Code Playgroud)
我试图了解如何通过sentences传递到reduce--我失败的尝试来编写此内容:
reduce(sentences, str_count, pattern = "This") # FAILS! unused argument (.x[[i]])
reduce(sentences, ~ str_count, pattern = "This") # FAILS! Returns signature for str_count()
reduce(sentences, ~ str_count(pattern = "This")) # FAILS! Argument "string" missing with no default.
reduce(sentences, ~ str_count("This")) # FAILS! Returns wrong result, 4.
reduce(sentences, ~ str_count(.x, pattern = "This") + str_count(.y, …Run Code Online (Sandbox Code Playgroud) 我要寻找一个tidyverse/purrr方法将元素添加到列表中。例如:
library(tidyverse)
l <- list(c("a", "a", "b"), c("c", "d"), c("e", "f", "e", "g"))
l
[[1]]
[1] "a" "a" "b"
[[2]]
[1] "c" "d"
[[3]]
[1] "e" "f" "e" "g"
Run Code Online (Sandbox Code Playgroud)
如何构建管道%>%以返回如下内容:
desired <- list(
list(vec = c("a", "a", "b"), length = 3, unique = 2),
list(vec = c("c", "d"), length = 2, unique = 2),
list(vec = c("e", "f", "e", "g"), length = 4, unique = 3)
)
desired
[[1]]
[[1]]$vec
[1] "a" "a" "b" …Run Code Online (Sandbox Code Playgroud)