有没有办法locator()
在RStudio情节缩放中启用功能?这仅适用于RStudio的较小窗口(默认右下角),但是当您单击已作为单独窗口打开的查看器时,不会捕获任何坐标:
plot(iris$Petal.Width, iris$Petal.Length)
locator()
Run Code Online (Sandbox Code Playgroud)
也许这里的答案是目前没有实现,这就是为什么我在网上找不到它的原因.
我正在使用RStudio版本0.99.491.
提前致谢.
我正在尝试制作一个使用渲染的rmarkdown文档render()
.该render
调用有两个参数化元素:
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) 我试图用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) 我正在尝试制作一系列用于比较的图.比如说,我想使用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) 这是一个关于MS Access的新手问题.所以新手,我不知道如何正确地提出有关MS Access的问题.所以请原谅任何违法行为.
假设我有一个包含以下字段的数据库:
现在高度是以厘米为单位的度量.说出我们的高度测量值出了问题,对于某些日期和组,而不是厘米,英寸输入数据库.假设有太多的值实际上在数据库中更改它们.所以我需要使用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) 使用下面的示例,我试图找出一种向我闪亮的应用程序添加功能的方法,以便执行以下操作:
基本上我希望能够点击地图上的车站或用键盘手动输入车站。
这可以用传单吗?我已经看到使用 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) 我想对一列应用几个函数,但我想应用一些关于何时执行此操作的逻辑,在这种情况下,当另一列有一些 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后在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) 在四开本中定义新标注的最佳调用方式是什么?我可以像这样修改默认标注:
---
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)
但适用于所有后续标注。定义新的最好方法是什么?
我喜欢使用这个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 ×8
ggplot2 ×2
r-markdown ×2
centos ×1
contour ×1
css ×1
curl ×1
data.table ×1
date ×1
interactive ×1
kableextra ×1
leaflet ×1
linux ×1
ms-access ×1
plot ×1
quarto ×1
readxl ×1
rstudio ×1
shiny ×1