我有一些作者与他们所在的城市或国家.我想知道是否可以在地图上绘制具有国家坐标的共同作者网络(图1).请考虑来自同一国家的多位作者.[编辑:可以在示例中生成多个网络,并且不应显示可避免的重叠].这适用于数十位作者.需要缩放选项.Bounty承诺+50为未来的工作答案.
refs5 <- read.table(text="
row bibtype year volume number pages title journal author
Bennett_1995 article 1995 76 <NA> 113--176 angiosperms. \"Annals of Botany\" \"Bennett Md, Leitch Ij\"
Bennett_1997 article 1997 80 2 169--196 estimates. \"Annals of Botany\" \"Bennett MD, Leitch IJ\"
Bennett_1998 article 1998 82 SUPPL.A 121--134 weeds. \"Annals of Botany\" \"Bennett MD, Leitch IJ, Hanson L\"
Bennett_2000 article 2000 82 SUPPL.A 121--134 weeds. \"Annals of Botany\" \"Bennett MD, Someone IJ\"
Leitch_2001 article 2001 83 SUPPL.A 121--134 weeds. \"Annals of …Run Code Online (Sandbox Code Playgroud) 在类似的帖子中(如何在R Shiny中对齐一组checkboxGroupInput)复选框仅垂直对齐(如在我的示例中)或仅水平对齐(R Shiny在水平方向上显示checkboxGroupInput).我想知道是否有办法在两种意义上实现这一点(在列中时).
library(shiny)
examplesubset<-read.table(text="
elements locations
element_One A,M,P,R
element_Two A,B,C,M,P,E,I
element_Three G,M,T,F,O,H,A,B,C,D" , header=TRUE, stringsAsFactors=FALSE)
examplesubset$elements<-as.factor(examplesubset$elements)
ui<-fluidPage(
tags$head(tags$style(HTML("
.multicol {
-webkit-column-count: 3; /* Chrome, Safari, Opera */
-moz-column-count: 3; /* Firefox */
column-count: 3;
-moz-column-fill: auto;
-column-fill: auto;
}
"))),
titlePanel("Panel"),
sidebarLayout(
sidebarPanel(
selectInput("elements", "Select elements:",
choices=examplesubset$elements)
) ,
mainPanel(
fluidRow(
column(3,
uiOutput("checkboxesui")
))))
)
server<-function(input, output,session) {
elementsselected<-reactive({
sp<-examplesubset[examplesubset$elements==input$elements,]
sp<-droplevels(sp)
})
locationsreactive<- reactive({
j<-as.factor(unique(unlist(strsplit(elementsselected()$locations, ",", fixed = TRUE) ) ) )
j<-droplevels(j)
})
output$checkboxesui<-renderUI({ …Run Code Online (Sandbox Code Playgroud) 我想合并两个列表以保留每个对象的索引:
mylist<-list(1,NULL,2)
otherlist<-list(NULL,3,NULL,4,5,6)
# Desired
list(1,3,2,4,5,6)
# my try:
suppressWarnings(mapply(c, mylist, otherlist) )
Run Code Online (Sandbox Code Playgroud)
答案应该是普遍的
编辑:为了避免类似问题的扩散。我决定在这里也请求保留属性的可能性(最好是带有基数)。
mylist<-list(1,NULL,2)
attr(mylist[[1]],"at")<-"a"
attr(mylist[[3]],"at")<-"c"
otherlist<-list(NULL,3,NULL,4,5,6)
attr(otherlist[[2]],"at")<-"b"
attr(otherlist[[4]],"at")<-"d"
attr(otherlist[[5]],"at")<-"e"
attr(otherlist[[6]],"at")<-"f"
Run Code Online (Sandbox Code Playgroud) 我有一个大数据框,我希望字符串基于后缀(子字符串)在列中对齐,源数据框如下所示:
notst代表要忽略的其他变量前缀
# col1 col2 col3
# notst-s1 notst-s2 notst-x3
# notst-s1 notst-x3 notst-a5
# notst-s2 notst-a5
# notst-x3 notst-a5
Run Code Online (Sandbox Code Playgroud)
结果应该是:
# col1 col2 col3 col4
# notst-s1 notst-s2 notst-x3
# notst-s1 notst-x3 notst-a5
# notst-s2 notst-a5
# notst-x3 notst-a5
Run Code Online (Sandbox Code Playgroud)
编辑:考虑整个后缀(在" - "之后).它没有数字.在某些情况下,整个字符串("xxxx-spst")应匹配(*),因为字符串的xxxx部分有多个版本.
对于:
df <- read.table(text="
col1 col2 col3
st1-ab stb-spst sta-spst
stc-spst sta-spst st4-ab
stb-spst st7-ab
st9-ba stb-spst",header=TRUE,fill=TRUE,stringsAsFactors=FALSE)
Run Code Online (Sandbox Code Playgroud)
可能的结果可能是:(列名和顺序无关)
# col1 col2 col3 col4
# st1-ab stb-spst sta-spst
# st4-ab stc-spst sta-spst
# st7-ab stb-spst
# stb-spst st9-ba …Run Code Online (Sandbox Code Playgroud) 我试图使用函数获取每组数据帧的3个最常见数字,但忽略不太常见的值(每组),并允许唯一数字(如果存在).接受的答案将是最低的system.time
#my current function
library(plyr)
get.3modes.andcounts<- function(origtable,groupby,columnname) {
data <- ddply (origtable, groupby, .fun = function(xx){
c(m1 = paste(names(sort(table(xx[,columnname]),decreasing=TRUE)[1])),
m2 = paste(names(sort(table(xx[,columnname]),decreasing=TRUE)[2])),
m3 = paste(names(sort(table(xx[,columnname]),decreasing=TRUE)[3])),
counts=length2(xx[[columnname]], na.rm=TRUE) #http://www.cookbook-r.com/Manipulating_data/Summarizing_data/
) } )
return(data)
}
length2 <- function (x, na.rm=FALSE) {
if (na.rm) sum(!is.na(x))
else length(x)
}
# example df
col2<-c(4, 4, 4, 4, 5, 3, 3, 3, 2, 2, # group1 "5" is the less common
2, 2, 2, 4, 4, 3, 3, 2, 2, 2, # group2 "3" and …Run Code Online (Sandbox Code Playgroud) 我有一个带有多个参考书目 (MB) 的 R 包小插图,使用lua 过滤器。当我尝试将带有 MB 的小插图变成 pkgdown 文章时,我收到了 .lua 和 .bib 文件的错误,这些错误没有与小插图一起出现。
pkgdown::build_article("index", pkg = ".", data = list(), lazy = FALSE,
quiet = FALSE) # build index.Rmd vignette (located in vignettes folder) as article
openBinaryFile: does not exist (No such file or directory
Run Code Online (Sandbox Code Playgroud)
变通方法:如果我使用整个文件路径,问题就会消失: /home/user..
注意:对于 pandoc >2.11,每个参考书目只接受一个 .bib
带有 MB 的 Vignette (index.Rmd),示例 yaml 部分:
pkgdown:
as_is: true
output:
rmarkdown::html_vignette:
toc: true
toc_depth: 1
number_sections: true
pandoc_args: --lua-filter=multiple-bibliographies.lua
bibliography_normal: [allrefs.bib]
bibliography_software: [packages.bib, Rrefs.bib]
bibliography_docs: …Run Code Online (Sandbox Code Playgroud) 以下css样式对应于闪亮的仪表板中的菜单图标。我想改变它。我试过了tags$head(tags$style..,但没有用。有任何想法吗?
.main-header .sidebar-toggle:before {
content: "\f0c9";
}
Run Code Online (Sandbox Code Playgroud) 我想请一些方法来预测R中的lm(线性模型),它接受反应变量.
如果你有一个带有y和x的线性模型"lm",那么可以为新数据提供"预测",为x提供新值.我想在闪亮的应用程序中为反应性y和x做到这一点
在下面的工作示例中,我以某种方式(任意地,只是为了使其工作)创建了lm的反应y和x值,并且还创建了一个输入以提供更改的新值(用作新x).
目标是在考虑y(),x()的情况下正确地获得新(输入)x的预测y.
library(shiny)
library(EnvStats)
ui <- fluidPage (
sidebarLayout(
sidebarPanel (
numericInput('variable1', 'new x', 0.1, min = 0, max = 100, step = 0.1)
),
mainPanel (plotOutput('plot1') )
)
)
server <- function(input, output){
# Initial data and linear regression that should be reactive,
# the dependency on input$variable1<1 is just an example to work with a lm based on reactive data.
y<- reactive (
if (input$variable1<1)
{ y <- c(3.1, 3.25, 3.5, 4, 3.5, 5, 5.5) } …Run Code Online (Sandbox Code Playgroud) 这是一个圆角正方形的代码,我想知道它是否可以由一个代替的鼠形,这是一个非常相似的数字。
在维基百科指出:
尽管构造一个圆角的正方形在概念上和物理上可能更简单,但是该鼠形方程式更简单并且可以更容易地泛化。
{
x<-c(1,1,0,0)
y<-c(1,0,0,1)
rad <- max(x)/7
ver<-25
yMod<-y
yMod[which(yMod==max(yMod))]<-yMod[which(yMod==max(yMod))]-rad
yMod[which(yMod==min(yMod))]<-yMod[which(yMod==min(yMod))]+rad
topline_y<-rep(max(y),2)
topBotline_x<-c(min(x)+rad, max(x)-rad)
bottomline_y<-rep(min(y),2)
pts<- seq(-pi/2, pi*1.5, length.out = ver*4)
ptsl<-split(pts, sort(rep(1:4, each=length(pts)/4, len=length(pts))) )
xy_1 <- cbind( (min(x)+rad) + rad * sin(ptsl[[1]]), (max(y)-rad) + rad * cos(ptsl[[1]]))
xy_2 <- cbind( (max(x)-rad) + rad * sin(ptsl[[2]]), (max(y)-rad) + rad * cos(ptsl[[2]]))
xy_3 <- cbind( (max(x)-rad) + rad * sin(ptsl[[3]]), (min(y)+rad) + rad * cos(ptsl[[3]]))
xy_4 <- cbind( (min(x)+rad) + rad * sin(ptsl[[4]]), (min(y)+rad) + rad …Run Code Online (Sandbox Code Playgroud) 我试图用逗号和“和”作为字符串中的分隔符连接动态变化的向量的元素。问题是,当字符向量只有一个元素时,我在字符串前有一个不需要的“和”。
vec <-c("something")
vec <-c("something","something")
vec <-c("something","something","something")
paste0(c(paste(head(vec, n=length(vec) -1), collapse = ", ") ,
"and", paste(tail(vec, n=1) )
),
collapse= " ")
[1] " and something" # not what is expected
[1] "something and something" # ok
[1] "something, something and something" #ok
Run Code Online (Sandbox Code Playgroud) 虽然可以在闪亮的仪表板应用程序中添加标题,但在应用程序页面中可以正确显示,
## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "my title"),
dashboardSidebar(),
dashboardBody()
)
server <- function(input, output) { }
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
它不会显示为浏览器选项卡的名称.由于浏览器中的选项卡名称只显示URL(如127 ...)实际上生成的html <title></title>在第一行中有字符串,所以我不能在它之前手动放置一个HTML标题字符串(仅在之后,这不起作用) ).