是否有任何简单的方法可以在ggplot2中与facet结合创建华夫饼块,或者与华夫饼包一起梳理?
例如,用100个方格替换下面的每个条形代表1%.
ggplot(mtcars, aes(x = factor(vs), y = hp, fill = as.factor(carb))) +
geom_bar(stat = 'identity', position = 'fill') +
facet_wrap('gear')
Run Code Online (Sandbox Code Playgroud) 我想导出以下模型,以便其他用户可以打开它并使用predict函数来预测新观察的类。这是它唯一的用途。我可以保存 mod_fit,但它会占用大量空间,最终用户可以访问我不想要的信息。有什么简便的方法吗?
library(caret)
library(dplyr)
iris2 <- iris %>% filter(Species != "setosa") %>% mutate(Species = as.character(Species))
mod_fit <- train(Species ~., data = iris2, method = "glm")
Run Code Online (Sandbox Code Playgroud) 我有一个包含1000万行的表,我试图找到谁是某些机器(id)的第一个/最后一个维护者,具体取决于某些日期,也取决于机器的状态.我的查询使用了六个连接,还有其他首选选项吗? 编辑:原始表有索引,试图优化查询替换连接 - 如果可能的话?SQL小提琴示例:
编辑(在下面添加了其他信息):
示例表:
CREATE TABLE vendor_info (
id INT,
datestamp INT,
statuz INT,
maintainer VARCHAR(25));
INSERT INTO vendor_info VALUES (1, 20180101, 0, 'Jay');
INSERT INTO vendor_info VALUES (2, 20180101, 0, 'Eric');
INSERT INTO vendor_info VALUES (3, 20180101, 1, 'David');
INSERT INTO vendor_info VALUES (1, 20180201, 1, 'Jay');
INSERT INTO vendor_info VALUES (2, 20180201, 0, 'Jay');
INSERT INTO vendor_info VALUES (3, 20180201, 1, 'Jay');
INSERT INTO vendor_info VALUES (1, 20180301, 1, 'Jay');
INSERT INTO vendor_info VALUES …Run Code Online (Sandbox Code Playgroud) 我已经加载了我的字体
library(extrafont)
font_import()
Run Code Online (Sandbox Code Playgroud)
当我查看路径时
fonttable()
Run Code Online (Sandbox Code Playgroud)
有一些字体在该路径下不再存在。这给我以后带来了一些问题。如何从字体数据库中删除/取消注册它们?
只是重新运行 font_import 是行不通的。
示例取自 Shiny 画廊。我想在第一个选项卡上显示 ex1 和 ex2,在第二个选项卡上的 ex2 和 ex2 之间有一些中断。
用户界面
navbarPage(
title = 'DataTable Options',
tabPanel('Display length', DT::dataTableOutput('ex1')),
tabPanel('Length menu', DT::dataTableOutput('ex2'))
)
Run Code Online (Sandbox Code Playgroud)
服务器
function(input, output) {
# display 10 rows initially
output$ex1 <- DT::renderDataTable(
DT::datatable(iris, options = list(pageLength = 25))
)
# -1 means no pagination; the 2nd element contains menu labels
output$ex2 <- DT::renderDataTable(
DT::datatable(
iris, options = list(
lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
pageLength = 15
)
)
)
}
Run Code Online (Sandbox Code Playgroud)
我认为下面的代码会起作用,但它不会。它确实在任何选项卡中显示任何内容。
navbarPage(
title = …Run Code Online (Sandbox Code Playgroud) Formattable 有一些简单的格式化表格选项,例如:
library(shiny)
library(DT)
library(formattable)
df <- formattable(iris, lapply(1:4, function(col){
area(col = col) ~ color_tile("red", "green")
Run Code Online (Sandbox Code Playgroud)
这以后可以coverted到DT数据表
df <- as.datatable(df)
Run Code Online (Sandbox Code Playgroud)
对我来说,在RStudion的Viewer中查看是完美的.但是,我想以某种方式将其部署为Shiny应用程序.完整代码:
library(DT)
library(shiny)
ui <- fluidPage(
DT::dataTableOutput("table1"))
server <- function(input, output){
df <- formattable(iris, lapply(1:4, function(col){
area(col = col) ~ color_tile("red", "green")
}))
df <- as.datatable(df)
output$table1 <- DT::renderDataTable(DT::datatable(df))
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
这不起作用,有什么工作吗?我喜欢条件格式formattable,但也想使用一些DT提供的选项,例如过滤,搜索,colvis等.
要将它部署为formattable有一个线程:
我正在关注以下备忘单:
https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf
并尝试使用以下代码制作一些列表(从备忘单中粘贴的副本)
---
title: "Test"
author: "Test"
date: "7 August 2017"
output: html_document # or pdf_document
---
* unordered list
* item 2
+ sub-item 1
+ sub-item 2
1. ordered list
2. item 2
+ sub-item 1
+ sub-item 2
Run Code Online (Sandbox Code Playgroud)
但结果与备忘单中的结果不同,圆圈不相同,子项目不会缩进.
进行一些 PCA 分析,并与FactoMineR函数的结果进行比较时,我没有得到相同的结果。一个例子PCAprcompbase
library(ISLR)
library(FactoMineR)
data("NCI60")
df <- NCI60$data
pca_prcomp <- prcomp(df, scale. = T)
pca_facto <- FactoMineR::PCA(df, scale.unit = T, graph = F, ncp = 65)
# One column is missing
dim(pca_prcomp$x)
dim(pca_facto$ind$coord)
# Values are similiare - but not the same
head(pca_prcomp$x[, 1:2])
head(pca_facto$ind$coord[, 1:2])
# Using scale function - does not return same values
pca_facto_scale <- PCA(scale(df), scale.unit = F, graph = F, ncp = 65)
head(pca_facto$ind$coord[, 1:2], 3)
head(pca_facto_scale$ind$coord[, 1:2], 3)
Run Code Online (Sandbox Code Playgroud) 有一个例子如何在checkBoxGroupInput这里添加国家标志
https://gist.github.com/bborgesr/f2c865556af3b92e6991e1a34ced2a4a
我试图稍微调整代码,以使用pickerinputshinywidgets 实现相同的结果.但是,在我的结果中,我没有看到任何图像.
library(shiny)
library(shinyWidgets)
countries <- c("Australia", "United Kingdom", "United States")
flags <- c(
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/au.svg",
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/gb.svg",
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/us.svg"
)
ui <- fluidPage(
pickerInput("countries", "countries", multiple = T,
choices = countries,
choicesOpt = list(content =
mapply(countries, flags, FUN = function(country, flagUrl) {
tagList(
tags$img(src=flagUrl, width=20, height=15),
country
)
}, SIMPLIFY = FALSE, USE.NAMES = FALSE)
))
,
textOutput("txt")
)
server <- function(input, output, session) {
output$txt <- renderText({
paste("You chose", paste(input$countries, collapse = ", "))
}) …Run Code Online (Sandbox Code Playgroud) 根据我的理解,输入应该转换为字符而不指定
"x = ...字符向量,或者要强制转换为字符向量的向量"
nchar(2015122514204000000)
# 18
nchar("2015122514204000000")
# 19
# Replacing the end zeroes with 111111
nchar(2015122514204111111)
# 19
Run Code Online (Sandbox Code Playgroud) r ×9
shiny ×3
datatables ×1
dt ×1
extrafont ×1
formattable ×1
ggplot2 ×1
join ×1
markdown ×1
pca ×1
r-caret ×1
sql ×1
sql-server ×1
string ×1
waffle-chart ×1