小编bos*_*hek的帖子

在RStudio中绘制缩放和定位器

有没有办法locator()在RStudio情节缩放中启用功能?这仅适用于RStudio的较小窗口(默认右下角),但是当您单击已作为单独窗口打开的查看器时,不会捕获任何坐标:

plot(iris$Petal.Width, iris$Petal.Length)
locator()
Run Code Online (Sandbox Code Playgroud)

也许这里的答案是目前没有实现,这就是为什么我在网上找不到它的原因.

我正在使用RStudio版本0.99.491.

提前致谢.

plot interactive r rstudio

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

为什么从rmarkdown渲染pdf需要在渲染之间关闭rstudio?

背景

我正在尝试制作一个使用渲染的rmarkdown文档render().该render调用有两个参数化元素:

  • 我希望用户能够指定pdf或html.直截了当使用output_format().
  • 我还想将一个参数传递给文档,以指定表(使用kableExtra包)是否为latex或html.

这是名为test.Rmd的rmarkdown文件

---
title: "Title"
author: "Zzz Zzzzzz"
params:
  table_format:
    value
---

```{r setup}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
library(kableExtra)

options(knitr.table.format = params$table_format) 
```

## Test table

```{r cars}
if (params$table_format == "latex"){
kable(iris[1:100,], booktabs = T) %>%
  kable_styling(latex_options = c("scale_down")) 
}

if (params$table_format == "html"){
kable(iris[1:100,]) %>%
  kable_styling(bootstrap_options = c("striped", "hover"))  %>%
  scroll_box(width = "500px", height = "600px")
}


params$table_format
```
Run Code Online (Sandbox Code Playgroud)

现在这里有两个渲染文件的调用:

rmarkdown::render("test.Rmd", output_format = "pdf_document", params = list( …
Run Code Online (Sandbox Code Playgroud)

r r-markdown kableextra

14
推荐指数
2
解决办法
2579
查看次数

对应于ggplot2中变量级别的轮廓级别

我试图用ggplot2绘制轮廓图,事实证明它比我想象的要困难一些.使用iris数据集,我能够生成这个图:

ggplot(iris, aes(x=Petal.Width, y=Petal.Length, fill=Sepal.Width)) +
  stat_density2d(geom="polygon", aes(fill=..level..))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我的问题是我似乎无法弄清楚如何显示 - 而不是密度值 - 原始Sepal.Width值.这是我尝试过的:

ggplot(iris, aes(x=Petal.Width, y=Petal.Length, z=Sepal.Width)) +
  geom_tile(aes(fill=Sepal.Width))+
  stat_contour(aes(colour=..level..)) 
Run Code Online (Sandbox Code Playgroud)

这会产生一个特别奇怪的错误消息:

 Warning message:
 Computation failed in `stat_contour()`:
 (list) object cannot be coerced to type 'double' 
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

ggplot(iris, aes(x=Petal.Width, y=Petal.Length, fill=Sepal.Width)) +
  stat_density2d(geom="polygon", aes(fill=Sepal.Width))
Run Code Online (Sandbox Code Playgroud)

最后这个:

ggplot(iris, aes(x=Petal.Width, y=Petal.Length, fill=Sepal.Width)) +
  geom_tile()
Run Code Online (Sandbox Code Playgroud)

任何人都可以推荐一个很好的方法来生成ggplot2中的等高线图,变量的值本身会产生轮廓的水平吗?

更新

stat_contour示例:

# Generate data
library(reshape2) # for melt
volcano3d <- melt(volcano)
names(volcano3d) <- c("x", "y", "z")

# Basic plot
ggplot(volcano3d, aes(x, y, …
Run Code Online (Sandbox Code Playgroud)

r contour ggplot2

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

手动设置scale_fill_distiller()的比例

我正在尝试制作一系列用于比较的图.比如说,我想使用iris数据集制作一个这样的情节,我已经过滤,只能查看setosa种类:

library(ggplot2)
library(dplyr)

iris %>%
  filter(Species=="setosa") %>%
  ggplot(aes(y = Sepal.Width, x = Sepal.Length, fill = Petal.Length)) +
  geom_tile(stat = "identity") +
  scale_fill_distiller(palette = "Spectral")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

现在,如果我想以同样的方式绘制多色物种,我可以这样做:

iris %>%
  filter(Species=="versicolor") %>%
  ggplot(aes(y = Sepal.Width, x = Sepal.Length, fill = Petal.Length)) +
  geom_tile(stat = "identity") +
  scale_fill_distiller(palette = "Spectral")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我的问题是这些情节的填充比例是不同的.我知道我可以facet_wrap解决这个问题,但我只想说我需要个别情节.我想要的是将相同的填充比例应用于两个图.理想情况下我想继续使用,scale_fill_distiller但由于该函数的值参数有点不同,我无法达到很远,所以我尝试了scale_fill_gradientn.首先我建立了fill_range这样的:

fill_range <- seq(min(iris$Petal.Length), max(iris$Petal.Length), by=0.2)
Run Code Online (Sandbox Code Playgroud)

然后我尝试将seq输入到values参数中,scale_fill_gradientn如下所示:

iris %>%
  filter(Species=="versicolor") %>%
  ggplot(aes(y = Sepal.Width, x = Sepal.Length, fill = Petal.Length)) +
  geom_tile(stat …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

将操作应用于具有不规则日期条件的数据字段

这是一个关于MS Access的新手问题.所以新手,我不知道如何正确地提出有关MS Access的问题.所以请原谅任何违法行为.

假设我有一个包含以下字段的数据库:

  • 组(文本字段; A级和B级)
  • 日期(日期字段; 2012年1月至2014年12月)
  • 年份(定义为年份:年份([日期]))
  • 高度(数字字段;厘米)

现在高度是以厘米为单位的度量.说出我们的高度测量值出了问题,对于某些日期和组,而不是厘米,英寸输入数据库.假设有太多的值实际上在数据库中更改它们.所以我需要使用MS Access工具来应用它.为简单起见,假设将英寸值除以0.4会将单位转换为厘米.

除了2013年10月4日和2013年10月5日正确输入之外,2012年和2013年的A组都错误输入了高度.

所以问题是,我如何(我的想法是在查询的设计视图中使用条件字段)使用上面指定的日期条件(包括10月例外)将高度从英寸转换为厘米?

即使把我指向正确的方向也会非常有帮助.我习惯了不同的编程语言,这使我难以从哪里开始.

更新 我急于开发一个简单的例子,我省略了我试图将此功能添加到现有查询.@winghei的答案可能很完美.但是我不清楚sql在我的查询中将它添加到我的exisitng 代码的位置.这是已经存在的代码:

SELECT LAKE.NAME_TXT AS [Group], TRAWL_TRIP.TRAWL_TRIP_DAT AS Trawl_Date, Year([TRAWL_TRIP_DAT]) AS [Year], SAMPLE.WEIGHT_NUM AS Height
FROM (((LAKE INNER JOIN STATION ON LAKE.LAKE_ID = STATION.LAKE_ID) INNER JOIN (NET_TYPE RIGHT JOIN (TRAWL_TYPE RIGHT JOIN TRAWL_TRIP ON TRAWL_TYPE.TRAWL_TYPE_ID = TRAWL_TRIP.TRAWL_TYPE_ID) ON NET_TYPE.NET_TYPE_ID = TRAWL_TRIP.NET_TYPE_ID) ON STATION.STATION_ID = TRAWL_TRIP.STATION_ID) INNER JOIN TRAWL ON TRAWL_TRIP.TRAWL_TRIP_ID = TRAWL.TRAWL_TRIP_ID) INNER JOIN (MATURITY_TYPE RIGHT JOIN (SPECIES_TYPE INNER JOIN SAMPLE ON …
Run Code Online (Sandbox Code Playgroud)

ms-access date

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

单击传单地图中的点作为闪亮绘图的输入

使用下面的示例,我试图找出一种向我闪亮的应用程序添加功能的方法,以便执行以下操作:

  1. 单击地图上的一个点
  2. 这会根据车站 AND 改变情节
  3. 将相应的电台输入到“点击电台”侧边栏中

基本上我希望能够点击地图上的车站或用键盘手动输入车站。

这可以用传单吗?我已经看到使用 plotly 的参考资料,这可能是最终的解决方案,但如果可能的话,我很乐意在不小的部分发布传单,因为我已经对传单做了很多工作。尽管这里有工作示例,但这与此问题类似:

library(shiny)
library(leaflet)
library(shinydashboard)
library(ggplot2)
library(dplyr)

data("quakes")
shinyApp(
  ui = dashboardPage(title = "Station Lookup",
                     dashboardHeader(title = "Test"),
                     dashboardSidebar(
                       sidebarMenu(
                         menuItem("Data Dashboard", tabName = "datavis", icon = icon("dashboard")),
                         menuItem("Select by station number", icon = icon("bar-chart-o"),
                                  selectizeInput("stations", "Click on Station", choices = levels(factor(quakes$stations)), selected = 10, multiple = TRUE)
                         )
                       )
                     ),
                     dashboardBody(
                       tabItems(
                         tabItem(tabName = "datavis",
                                 h4("Map and Plot"),
                                 fluidRow(box(width= 4,  leafletOutput("map")),
                                          box(width = 8, plotOutput("plot")))
                         )
                       )
                     )
  ), …
Run Code Online (Sandbox Code Playgroud)

r leaflet shiny

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

将函数应用于 data.table [R] 中具有条件的每一列

我想对一列应用几个函数,但我想应用一些关于何时执行此操作的逻辑,在这种情况下,当另一列有一些 NA 时。为了说明,我将向iris数据集添加一些 NA并将其转换为 data.table:

library(data.table)

irisdt <- iris
## Prep some example data
irisdt[irisdt$Sepal.Length < 5,]$Sepal.Length <- NA
irisdt[irisdt$Sepal.Width < 3,]$Sepal.Width <- NA

## Turn this into a data.table
irisdt <- as.data.table(iris)
Run Code Online (Sandbox Code Playgroud)

如果我想申请max多个列,我会这样:

## Apply a function to individual columns
irisdt[, lapply(.SD, max), .SDcols = c("Petal.Length", "Petal.Width")]
#>    Petal.Length Petal.Width
#> 1:          6.9         2.5
Run Code Online (Sandbox Code Playgroud)

然而,在这种情况下,我想取出任何不是 NA 的行,Sepal.Length然后返回 max 和 min 以及我为 NA 子集的列的名称。下面是一种丑陋的实现方式,但希望能说明我所追求的:

## Here is what the table would look like
desired_table …
Run Code Online (Sandbox Code Playgroud)

r data.table

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

无法在CentOS中安装软件包:无法加载Internet例程

我在更新R后在CentOS上的R中安装软件包时遇到了一些麻烦.下面是我尝试在R中安装软件包时会发生什么的示例:

> install.packages("ggplot2")
Installing package into '/home/albers/R/x86_64-pc-linux-gnu-library/3.2'
(as 'lib' is unspecified)
--- Please select a CRAN mirror for use in this session ---
Error in download.file(url, destfile = f, quiet = TRUE) :
  internet routines cannot be loaded
In addition: Warning message:
In download.file(url, destfile = f, quiet = TRUE) :
  unable to load shared object '/usr/local/lib64/R/modules//internet.so':
  /usr/local/lib64/R/modules//internet.so: undefined symbol: curl_multi_wait
HTTPS CRAN mirror

 1: 0-Cloud [https]                2: Austria [https]
 3: Chile [https]                  4: China (Beijing 4) [https]
 5: Colombia …
Run Code Online (Sandbox Code Playgroud)

linux curl r centos install.packages

6
推荐指数
2
解决办法
4374
查看次数

在四开中定义新标注

在四开本中定义新标注的最佳调用方式是什么?我可以像这样修改默认标注:

---
format: 
  html: 
    theme:
      - custom.scss
---


::: {.callout-tip appearance="minimal"}
Some wild callout
:::
Run Code Online (Sandbox Code Playgroud)

然后是一个.scss像这样的文件:

/*-- scss:defaults --*/
$callout-background: #ff5bbb;

/*-- scss:rules --*/

.callout {
    background-color:$callout-background;
 }
Run Code Online (Sandbox Code Playgroud)

但适用于所有后续标注。定义新的最好方法是什么?

css quarto

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

read_excel 读入消息 - 抑制?

我喜欢使用这个readxl包。但是,我一直将它用作 RMarkdown 文档的一部分,并且read_excel()读取文件时的一些消息在进行分析时很有用,但在尝试呈现分析时则不然。所以问题是,有什么方法可以在使用时抑制收到的消息(或与此相关的任何警告消息)read_excel?我将采用 RMarkdown 或 read_excel 解决方案。

以下是我想要抑制的消息类型的说明。出现在我的最终 Rmarkdown 文档中:

## Parsed with column specification:
## cols(
##   .default = col_character(),
##   Year = col_integer(),
##   Month = col_integer(),
##   Date = col_date(format = ""),
##   Day = col_integer(),
##   Replicate = col_integer(),
##   Time = col_integer(),
##   Depth = col_double(),
##   DenTotal = col_integer()
## )
## See spec(...) for full column specifications.
Run Code Online (Sandbox Code Playgroud)

我无法找到一种方法从 url 中读取 excel 文件,read_excel因此我无法在此处制作可重现的示例。

r r-markdown readxl

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