我用ggplot2找到了很多关于传说标题的话题但几个小时之后我无法处理我的情况.
这是数据集:
> dat
FACTOR1 FACTOR2 lsmean lower.CL upper.CL
1 A aa 26.2 25.6 26.8
2 B aa 24.8 23.9 25.7
3 A bb 26.0 25.2 26.7
4 B bb 24.9 23.9 25.9
5 A cc 24.4 23.9 24.8
6 B cc 23.9 22.9 25.0
7 A dd 24.9 24.3 25.6
8 B dd 23.2 22.3 24.0
Run Code Online (Sandbox Code Playgroud)
感兴趣的图形:
gp0 <- ggplot(dat, aes(x=FACTOR2, y=lsmean, group=FACTOR1, colour=FACTOR1))
( gp1 <- gp0 + geom_line(aes(linetype=FACTOR1), size=.6) +
geom_point(aes(shape=FACTOR1), size=3) +
geom_errorbar(aes(ymax=upper.CL, ymin=lower.CL), width=.1) + …Run Code Online (Sandbox Code Playgroud) 我试图在我闪亮的应用程序中添加第二个输入面板,其内容取决于第一个输入面板选择的输入,我试图吹嘘使用条件面板,但运气不好。
TO <-read.csv(“〜/ TO / TO / TO.csv”,sep =“;”)库(发光)
ShinyUI(fluidPage(
#应用程序标题titlePanel(“ dasboard”),
#带有滑动条输入的边栏,用于接收箱数
sidebarLayout(
sidebarPanel(
selectInput("country", label = h4("Pays"),
choices = levels(as.factor(TO$Pays))),
conditionalPanel(
condition = "input.country == 'Allemagne'",
selectInput("to", label = h4("Tour opérateur"),
choices = levels(as.factor(as.character(TO[as.character(TO$Pays)=="Allemagne",]$TO))))),
conditionalPanel(
condition = "input.country == 'Angleterre'",
selectInput("to", label = h4("Tour Operator"),
choices = levels(as.factor(as.character(TO[as.character(TO$Pays)=="Angleterre",]$TO)))))
Run Code Online (Sandbox Code Playgroud)
...
我发现的解决方案是为第一个inputPanel的每个值创建一个conditionalPanel,但是第二个inputPanel输出仅对第一个值正确。
有没有人有办法解决吗?
如何为图例指定标题plotly?我有一个堆积条形图,绘制不同的持续时间,如0-10,11-20.我希望传奇标题能说'持续时间'.
我想忽略pdf我的包中的所有文件(包括子文件夹中的文件)。写的正则表达式是什么.Rbuildignore?
根据“编写 R 扩展”,这应该是一个类似 perl 的正则表达式。但是,pdf当我编写与使用时匹配的模式时,这些文件不会被忽略grep(..., ..., perl=TRUE)。
我有以下代码:
plotfn= function(u) {
flt = filter(d, utensil ==u)
ggplot(flt,aes(x=p)) + geom_histogram(binwidth = 0.5, position= position_dodge(0.5), color="black",fill="cadetblue4")+ ggtitle("Histogram of P")+labs( x="P", y="Number of Observations")
}
lapply(unique(d$utensil),plotfn)
Run Code Online (Sandbox Code Playgroud)
我试图做一个par(mfrow= c(3,3))在一个屏幕上获得所有9个情节,但这是行不通的。我必须使用ggplot。
让我们A成为一个1 x 2 x 2阵列:
> A <- array(0, dim=c(1,2,2))
> A
, , 1
[,1] [,2]
[1,] 0 0
, , 2
[,1] [,2]
[1,] 0 0
Run Code Online (Sandbox Code Playgroud)
然后A[,,1]是无量纲的:
> A[,,1]
[1] 0 0
Run Code Online (Sandbox Code Playgroud)
我想拥有:
[,1] [,2]
[1,] 0 0
Run Code Online (Sandbox Code Playgroud)
这个drop论点没有产生我想要的东西:
> A[,,1,drop=FALSE]
, , 1
[,1] [,2]
[1,] 0 0
Run Code Online (Sandbox Code Playgroud)
我发现这很烦人.而且有问题,因为R识别向量矩阵的向量,而不是行矩阵.
我当然能做到matrix(A[,,1], 1, 2).有更方便的方式吗?
我有一张表在一个闪亮的应用程序中显示.我想根据值格式化表格并相应地对其进行着色.我已经看到了格式化区域着色,其中基于它定义断点的值的范围,然后生成应用于表格的颜色渐变.我想要做的是允许用户填充最小值和最大值,并根据它,表中的值将被着色.因此,如果值的范围为1-20,并且如果用户输入为5和15,则低于5且高于15的值不应对其应用任何颜色渐变.下面是我目前正在使用格式化区域格式的代码.
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(DT)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tab",
menuItem("1", tabName = "1")
)
)
body <- ## Body content
dashboardBody(box(width = 12,fluidRow(
fluidRow( column(
width = 3, textInput("text1", label = h5("Min"), value = "Enter min")),
column(
width = 3, textInput("text2", label = h5("Max"), value = "Enter max"))),
DT::dataTableOutput("op")
)))
ui <- dashboardPage(dashboardHeader(title = "Scorecard"),
sidebar,
body)
# Define the server code
server <- function(input, output,session) {
df <- data.frame(month = c("mazda 3", "mazda cx5", "mazda 6","mazda miata","honda …Run Code Online (Sandbox Code Playgroud) 我可以轻松地mesh3d在 R 中绘制一个图:
library(plotly)
x <- runif(50, 0, 110)
y <- runif(50, 0, 1)
z <- runif(50, 1, 2)
plot_ly(x = ~x, y = ~y, z = ~z, type = 'mesh3d')
Run Code Online (Sandbox Code Playgroud)
我想根据变量的值对表面进行着色z:高值对应于红色或橙色,中值对应于黄色或绿色,较小值对应于浅蓝色或蓝色。我的问题:我该如何使用mesh3d?
wireframe我使用包中的函数做了类似的事情lattice。
library(lattice)
x<-runif(12,0,1)
y<-runif(12,0,2)
grid<-expand.grid(x,y)
z<-grid$Var1 + grid$Var2^2
df<-data.frame(z=z,x=grid$Var1,y=grid$Var2)
# Note: there are 144 observations and I want 6 colors, so I need 144/6 = 24 replications for each color
nrow(df)
nrow(df)/6
a<-palette(c(rep("blue",24),rep("light blue",24),rep("green",24),rep("yellow",24),rep("orange",24),rep("red",24)))
wireframe(z~x + y,data=df,drape=T,col.regions=a)
Run Code Online (Sandbox Code Playgroud) 我想在 Shiny 的项目中包含字体很棒的selectizeInput图标。我该怎么办?
例如,给定一个算术表达式,x + y*z我想将其转换为add(x, multiply(y, z)).
> getAST <- function(ee) purrr::map_if(as.list(ee), is.call, getAST)
> getAST(quote(x + y*z))
[[1]]
`+`
[[2]]
x
[[3]]
[[3]][[1]]
`*`
[[3]][[2]]
y
[[3]][[3]]
z
Run Code Online (Sandbox Code Playgroud)
可以使用它rapply(result, as.character, how = "list")来获取字符而不是符号。
如何从这个 AST 中得到add(x, multiply(y, z))(结果)?当有一些括号时,这会变得更加复杂:
> getAST(quote((x + y) * z))
[[1]]
`*`
[[2]]
[[2]][[1]]
`(`
[[2]][[2]]
[[2]][[2]][[1]]
`+`
[[2]][[2]][[2]]
x
[[2]][[2]][[3]]
y
[[3]]
z
Run Code Online (Sandbox Code Playgroud)
我不要求答案必须使用该getAST功能。这只是一种可行的方法。
当然,在我的实际用例中,表达式更长。
这是没有括号时的情况的解决方案(我认为):
getAST <- function(ee) purrr::map_if(as.list(ee), is.call, getAST)
ast …Run Code Online (Sandbox Code Playgroud) r ×10
shiny ×4
ggplot2 ×2
arrays ×1
build ×1
dt ×1
font-awesome ×1
formattable ×1
graphics ×1
lattice ×1
package ×1
plotly ×1
r-plotly ×1
regex ×1
selectize.js ×1
shiny-server ×1