我在rmarkdown文档中有一个很长的标题,我想强制在特定位置换行.
最小例子:
---
title: "Quite long title want the * line break at the asterisk"
output: html_document
---
Run Code Online (Sandbox Code Playgroud)
我试过了:\n,\newline,\\和手动换行符.他们似乎都没有工作.
我认为它必须非常简单,但我无法找到解决方案.
我正在尝试使用rmarkdown创建一个文档,其中包括来自rCharts包的图和使用htmlwidgets中包含的DT库的数据表.出于某种原因,我不能一起显示它们.
---
title: "Untitled"
output: html_document
---
```{r, echo=FALSE}
library(DT)
library(rCharts)
df<-data.frame(Name=c("a","Z","h","k","j"),Value=(sample(10^7,5)))
datatable(df, filter = 'top', options = list(
pageLength = 10,iDisplaylength=10, autoWidth = TRUE
))
```
```{r, message=FALSE, echo=FALSE, results='asis'}
df<-data.frame(label=c("One","Two","Three"),valuea=c(1,2,3),
othera=c(10,11,12),stringsAsFactors = FALSE)
p1 <- nPlot(valuea~ label, data = df, type = 'pieChart')
#Different options I tried
p1$print('inline', include_assets = TRUE, cdn = FALSE)
#p1$show('inline', include_assets = TRUE, cdn = FALSE)
#p1$print('inline', include_assets = TRUE)
#p1$show('inline', include_assets = TRUE)
#These provide an error
#p1$print('inline', include_assets = TRUE, cdn …Run Code Online (Sandbox Code Playgroud) 我必须每天生成一个甘特图.我的想法是使用R的DiagrammeR包中包含的美人鱼api.
我的数据总是具有相同的结构,因此,我创建了一个非常原始的解析器,它包含在可重现的示例中.
我面临的问题是,在4个部分后,样式从零开始:
rect.section.section0
rect.section.section1
rect.section.section2
rect.section.section3
rect.section.section0
Run Code Online (Sandbox Code Playgroud)
我可以改变rect.section.sectionx.css的颜色,但我不能添加新颜色.
有没有办法改变/个性化该部分的颜色/样式?
我可R重复的例子:
library(DiagrammeR)
library(htmltools)
fromdftogantt<-function(df,Title="Proba",filename="proba.html"){
txt<-paste("gantt","dateFormat YYYY-MM-DD",paste("title",Title),"",sep="\n")
for(i in unique(df$section)){
txt<-paste(txt,paste("section",i),sep="\n")
for(j in which(df$section==i)){
txt<-paste(txt,paste0(df$name[j],":",df$status[j],",",
df$fecini[j],",",
df$fecfin[j]),sep="\n")
}
txt<-paste0(txt,"\n")
}
m<-mermaid(txt)
m$x$config = list(ganttConfig = list(
axisFormatter = list(list(
"%m-%Y"
,htmlwidgets::JS(
'function(d){ return d.getDate() == 1 }'
)
))
))
save_html(as.tags(m),file=filename)
}
df<-data.frame(section=letters[1:6],name=paste("Name",1:6),
status=rep("active",6),
fecini=as.Date(c("2015-02-03","2015-03-05","2015-04-07",
"2015-02-03","2015-03-05","2015-04-07")),
fecfin=as.Date(c("2015-06-01","2015-04-30","2015-12-31",
"2015-06-01","2015-04-30","2015-12-31")),
stringsAsFactors = FALSE)
fromdftogantt(df,Title="Proba",filename="proba.html")
Run Code Online (Sandbox Code Playgroud) 我想用rCharts的NVD3 lineChart图使用area = true选项绘制不同种群的分布,如http://nvd3.org/examples/line.html.
我在这里工作:
require(devtools)
install_github('ramnathv/rCharts')
require(rCharts)
df<-data.frame(X=rep(1:4,2),Y=1:8,fil=c(rep("A",4),rep("B",4)))
denp <- nPlot(Y ~ X, group = 'fil', data = df, type = 'lineChart')
denp$chart(color =c('#ff7f0e', 'blue', 'green'))
denp$yAxis(axisLabel= 'Density')
denp$xAxis(axisLabel= 'Value')
denp$chart(margin = list(left=80,bottom=80))
denp$yAxis(tickFormat = "#!function (x,y,e) { return }!#")
denp$xAxis(tickFormat = "#!function (x,y,e) {
tickformat = ['0,01','0,1',1,10,100,1000,10000,'100k'];
return tickformat[x+2];}!#")
denp$chart(tooltipContent = "#! function(key, val, e, graph){
return '<h3>' + '<font color=blue>'+ key +'</font>'+ '</h3>' + '<p>'+ val } !#")
denp
Run Code Online (Sandbox Code Playgroud)
我发现的问题是我无法将area参数切换为true.我试过了:
denp$chart(area=TRUE)
denp$chart(area=c(TRUE,TRUE,TRUE))
denp$chart(area=c('true'))
denp$chart(area=c('true','true','true'))
denp$chart(area=c('#!true!#')) …Run Code Online (Sandbox Code Playgroud) 我用图表时间序列dygraphs中R像下面这样:
library(dygraphs)
library(htmlwidgets)
library(data.table)
now <- Sys.time()
dataset <- data.table(time = as.POSIXct(now+1:10),value = 1:10)
d <- dygraph(dataset)
Run Code Online (Sandbox Code Playgroud)
图例中显示的日期格式取决于机器区域设置,我不能将其保留.
x轴的标签可以格式化如下:
valueFormatter<-"function formatValue (ms) {
return ms.toISOString();
}"
d <- d%>%dyAxis("x", axisLabelFormatter=JS(valueFormatter))
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何为传奇做到这一点.
我试图用R中的gooogleVis制作一个带有两个坐标和一个尺寸参数的气泡图.
当我没有建立颜色变量时,size变量用作颜色而不是大小.我可以包含colorvar但是变量会显示在工具提示中.
我该如何避免这种行为?
我包含了前面提到的两个案例的最小工作示例:
library(googleVis)
set.seed(1)
bubbledata<-data.frame(id=rep("",100),X=sample(10,10,rep=TRUE),
Y=sample(10,10,rep=TRUE),Weight=sample(10,10,rep=TRUE))
# This graph uses sizevar as colorvar
bubble <- gvisBubbleChart(bubbledata, idvar="id",
xvar="X", yvar="Y",colorvar="",
sizevar="Weight")
plot(bubble)
bubbledata$colour<-""
# The output of this one is ok but the tooltip includes the colour var
bubble2 <- gvisBubbleChart(bubbledata, idvar="id",
xvar="X", yvar="Y",colorvar="colour",
sizevar="Weight")
plot(bubble2)
Run Code Online (Sandbox Code Playgroud) 我使用这种方法在 Shiny 中做了一个动画 我发现的问题是从情节到情节的过渡有点卡住(处理下一个情节时情节区域逐渐消失)。
我想保留之前的情节,直到下一个准备好。有没有办法从一个渲染图过渡到下一个渲染图,避免对先前图的淡化效果?
下面我包括一个最小的工作示例。如果您的计算机没有卡住,只需增加 K,它最终就会卡住。
library(shiny)
library(ggplot2)
k<-50000L
data=data.frame(x=runif(k),y=runif(k))
runApp(list(
ui =fluidPage(
tags$head(tags$style(".rightAlign{float:right;}")),
headerPanel("Cost Explorer"),
sidebarPanel(
actionButton("goButton", "Go!"),
actionButton("reset", "Reset") ),
mainPanel(fluidRow(column(8,
plotOutput(outputId="tsplot"),class = 'rightAlign')))),
server=function(input, output, session) {
datareactive<-reactiveValues(data=data)
t <- reactiveValues(counter=1)
observe({
isolate({
t$counter=t$counter+1;
datareactive$data<-data.frame(x=runif(k),y=runif(k))
})
if ((input$goButton > 0)){
invalidateLater(200, session)
}
})
output$tsplot <- renderPlot({
ggplot(datareactive$data,aes(x,y))+geom_point()+coord_fixed()+
theme_bw()+
geom_path(data=datareactive$data[(k-10):k,],aes(x,y),size=1.1,
colour="blue")+
geom_point(data=datareactive$data[k,],aes(x,y),
colour="red")
})
}
))
Run Code Online (Sandbox Code Playgroud) 我想创建像时间轴这个用R的timevis包.我知道如何在演示中建立一个组:
library(timevis)
dataGroups <- data.frame(
id = 1:11,
content = c(
"Open",
"Open",
"Open",
"Open",
"Half price entry",
"Staff meeting",
"Open",
"Adults only",
"Open",
"Hot tub closes",
"Siesta"
),
start = c(
"2016-05-01 07:30:00",
"2016-05-01 14:00:00",
"2016-05-01 06:00:00",
"2016-05-01 14:00:00",
"2016-05-01 08:00:00",
"2016-05-01 08:00:00",
"2016-05-01 08:30:00",
"2016-05-01 14:00:00",
"2016-05-01 16:00:00",
"2016-05-01 19:30:00",
"2016-05-01 12:00:00"
),
end = c(
"2016-05-01 12:00:00",
"2016-05-01 20:00:00",
"2016-05-01 12:00:00",
"2016-05-01 22:00:00",
"2016-05-01 10:00:00",
"2016-05-01 08:30:00",
"2016-05-01 12:00:00",
"2016-05-01 16:00:00", …Run Code Online (Sandbox Code Playgroud) 我必须合并许多 Spark DataFrame。合并后,我想在具有相同名称的多个列之间执行合并。
我能够根据这个问题创建一个最小的例子。
但是,我需要一段更通用的代码来支持:一组要合并的变量(在示例中set_vars = set(('var1','var2')))和多个连接键(在示例中join_keys = set(('id')))。
是否有更简洁(更通用)的方法来获得此结果pyspark?
df1 = spark.createDataFrame([
( 1, None , "aa"),
( 2 , "a", None ),
( 3 , "b", None),
( 4 , "h", None),],
"id int, var1 string, var2 string",
)
df2 = spark.createDataFrame([
( 1, "f" , "Ba"),
( 2 , "a", "bb" ),
( 3 , "b", None),],
"id int, var1 string, var2 string",
)
df1 = df1.alias("df1")
df2 = …Run Code Online (Sandbox Code Playgroud)