小编nei*_*fws的帖子

R plot() - 为什么我的点显示为水平线

我正在尝试在 R 中绘制一个图。我的 x 轴是转换为因子的周数,而我的 y 轴是一个数量。
当我跑plot()而不是点时,我会得到水平线。
为什么会发生这种情况?
这是一个示例数据集:

df <- data.frame(fin_week=as.factor(seq(1,20, by =1)), amount=(rnorm(20)^2)*100)
plot(df)
Run Code Online (Sandbox Code Playgroud)

plot r

1
推荐指数
1
解决办法
1689
查看次数

让 ioslides 默认为宽屏

在 ioslides 中,您可以通过按“w”使幻灯片宽屏。css 或 yaml 标头中是否有任何设置可以使宽屏成为默认设置?

r r-markdown ioslides

1
推荐指数
1
解决办法
880
查看次数

将操作按钮与 R flexdashboard 一起使用

是否可以在 R flexdashboard 中使用操作按钮?

例如,在下面的代表中,是否可以添加一个按钮,以便代码仅在显示按钮时运行?

我在网站上找不到文档https://garrettgman.github.io/rmarkdown/flexdashboard/using.html#html_widgets

谷歌处理的大部分信息都是在“纯粹”的闪亮应用程序中使用操作按钮而不是flexdashboard。

---
title: "example"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
```

Column {data-width=100}
-----------------------------------------------------------------------

### Chart A

```{r}
numericInput("n1", "First number", 10)  


```

Column {data-width=900}
-----------------------------------------------------------------------

### Chart B

```{r}

DT::renderDataTable({
  

x = sample(1:input$n1, size=500, replace=TRUE)
x= as.data.frame(x)

  DT::datatable(x, options = list(
    bPaginate = FALSE
  ))
})


```
Run Code Online (Sandbox Code Playgroud)

r shiny flexdashboard

1
推荐指数
1
解决办法
2147
查看次数

使用 as.yearqtr 转换 YYYYQ

我有一个格式为 YYYYQ 的 char 字段(例如 20124、20131 等),我想使用 Zoo 包中的 as.yearqtr 将其转换为字段格式。

感谢您的帮助!

r date date-format zoo

0
推荐指数
1
解决办法
9669
查看次数

无法打开在 R 中创建的栅格

我有两个与该错误相关的问题:

第一:我有一个合并的 dem 层和多个 shapefile,我创建了一个蒙版 shapefile 边界列表,我能够绘制所有这些,除了一个“第一个”,它是最大的一个:

> plot(DEM_masked_list[[1]])

Error in file(fn, "rb") : cannot open the connection
In addition: Warning message:
  In file(fn, "rb") :
  cannot open file '/private/var/folders/2w/rjzwcrbn3pg0jmsrfkz7n52h0000gn/T/RtmpkL8Ot5/raster/r_tmp_2018-01-29_014745_982_20879.gri': No such file or directory
Run Code Online (Sandbox Code Playgroud)

我注意到第一个 dem 的数据源与所有其他 dem 不同,这可能是由于它的尺寸较大(单元格数量为 509141570)!

DEM_masked_list

[[1]]
class       : RasterLayer 
dimensions  : 20015, 25438, 509141570  (nrow, ncol, ncell)
resolution  : 9.259259e-05, 9.259259e-05  (x, y)
extent      : -70.43231, -68.07694, 45.98676, 47.84  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs 
data source …
Run Code Online (Sandbox Code Playgroud)

r raster temporary-files

0
推荐指数
1
解决办法
2209
查看次数

在 R Shiny 应用程序中渲染 ggplot2 和绘图对象

我有一个R shiny应用程序使用R和来生成plotlyggplot2显示数字。

因为渲染plotly图形shiny需要plotly函数,所以renderPlotly图形ggplot2会转换为零件plotly中的对象renderPlotly,这会让它们有点混乱。

这是一个例子。首先,生成一些数据:

set.seed(1)

meta.df <- data.frame(cell = c(paste0("c_",1:1000,"_1w"), paste0("c_",1:1000,"_2w"), paste0("c_",1:1000,"_3w")),
                      cluster = c(sample(c("cl1","cl2","cl3"),1000,replace=T)),
                      age = c(rep(1,1000),rep(2,1000),rep(3,1000)),
                      x = rnorm(3000), y = rnorm(3000))

expression.mat <- cbind(matrix(rnorm(20*1000,1,1), nrow=20, ncol=1000, dimnames=list(paste0("g",1:20),meta.df$cell[1:1000])),
                        matrix(rnorm(20*1000,2,1), nrow=20, ncol=1000, dimnames=list(paste0("g",1:20),meta.df$cell[1001:2000])),
                        matrix(rnorm(20*1000,3,1), nrow=20, ncol=1000, dimnames=list(paste0("g",1:20),meta.df$cell[2001:3000])))
Run Code Online (Sandbox Code Playgroud)

这是应用程序代码:

library(shiny)
library(dplyr)
library(ggplot2)
library(ggpmisc)

server <- function(input, output, session)
{
  output$gene <- renderUI({
      selectInput("gene", "Select Gene to Display", choices …
Run Code Online (Sandbox Code Playgroud)

r render ggplot2 shiny plotly

0
推荐指数
1
解决办法
2123
查看次数

dplyr:如何将字符串传递给 dplyr 的 mutate 参数

我想编写一个辅助函数,一次性总结 A、B 和 C 列的百分比变化。我想在 rlang 的帮助下将字符串传递给 dplyr 的“mutate”参数。不幸的是,我收到一条错误消息,说我有一个意外的“,”。可以请您看一下吗?提前致谢!

library(rlang) #read text inputs and return vars
library(dplyr)


set.seed(10)
dat <- data.frame(A=rnorm(10,0,1),
                  B=rnorm(10,0,1),
                  C=rnorm(10,0,1),
                  D=2001:2010)

calc_perct_chg <- function(input_data,
                           target_Var_list,
                           year_Var_name){

      #create new variable names
          mutate_varNames <- paste0(target_Var_list,rep("_pct_chg = ",length(target_Var_list)))

      #generate text for formula
          mutate_formula  <- lapply(target_Var_list,function(x){output <- paste0("(",x,"-lag(",x,"))/lag(",x,")");return(output)})
          mutate_formula  <- unlist(mutate_formula) #convert list to a vector

      #generate arguments for mutate
          mutate_args <<- paste0(mutate_varNames,collapse=",",mutate_formula)

      #data manipulation
           output <- input_data %>% 
                         arrange(!!parse_quo(year_Var_name,env=caller_env())) %>% 
                         mutate(!!parse_quo(mutate_args,env=caller_env()))
      #output data frame
          return(output)
}



# error: unexpected ',' …
Run Code Online (Sandbox Code Playgroud)

r dataframe dplyr tidyverse

0
推荐指数
1
解决办法
990
查看次数