也许我缺少了一些东西,但是我似乎无法使dplyr的取消引用运算符与filter函数一起使用。它与select一起执行,但与filter无关。
例
set.seed(1234)
A = matrix(rnorm(100),nrow = 10, ncol = 10)
colnames(A) <- paste("var", seq(1:10), sep = "")
varname_test <- "var2"
A <- as_tibble(A)
select(A, !!varname_test) #this works as expected
# this does NOT give me only the rows where var2
# is positive
(result1 <- filter(A, !!varname_test > 0))
# This is how the result 1 should look like
(result2 <- filter(A, var2 > 0))
# result1 is not equal to result2
Run Code Online (Sandbox Code Playgroud)
我将不胜感激任何帮助!
在 Windows 10 上,我尝试将 Jupyter 笔记本另存为 pdf,其名称会随着笔记本的每次运行而更改。
这是我到目前为止所拥有的:
name1 = 'July'
name2 = 'August'
jupyter_nb_filename = '{}_vs_{}'.format(name1,name2)
!jupyter nbconvert --output-dir="C:\\mydir\\" --output=jupyter_nb_filename --to pdf --TemplateExporter.exclude_input=True mynotebook.ipynb
Run Code Online (Sandbox Code Playgroud)
我查看了文档但无法弄清楚。
任何帮助将不胜感激。
我有 10 组数据点,我正在尝试为要在绘图上显示的每个组添加平均值(例如,通过不同的符号,如大三角形或星形或类似的东西)。这是一个可重现的例子
library(ggplot2)
library(reshape2)
set.seed(1234)
x <- matrix(rnorm(100),10,10)
varnames <- paste("var", seq(1,10))
df <- data.frame(x)
colnames(df) <- varnames
melt(df)
ggplot(data = melt(df)) + geom_point(mapping = aes(x = variable, y = value))
mymeans <- colMeans(df)
Run Code Online (Sandbox Code Playgroud)
基本上我现在想mymeans在各自的变量位置绘制值,有人知道如何快速做到这一点吗?
我试图使用ggplot2在两个变量的每个点之间绘制一条直线,这两个变量是同时观察到的.我查看了geom_segment,但我很难在我的案例中使其工作.
这是我最小的工作示例和我想要实现的图画(我缺少的部分是蓝色).
我将不胜感激任何帮助!
set.seed(1234)
y <- rnorm(10,0,0.01)
Date <- seq(as.Date("2000/1/1"), by = "day", length.out = 10)
example_df <- tibble(Date,y) %>% mutate(avg = mean(y))
ggplot(example_df, mapping = aes(x = Date)) + geom_point(mapping = aes(y = y)) +
geom_line(aes(y = y)) +
geom_line(aes(y = avg), col = "red")
Run Code Online (Sandbox Code Playgroud)