我想要一个区域的图,比如拉丁美洲,使用来自IPUMSI的世界形状文件......
https://international.ipums.org/international/resources/gis/IPUMSI_world.zip
...我稍后会添加一些IPUMS区域,所以我真的想用它作为我的模板层.
当我coord_map在ggplot2中添加限制时,我对绘图有困难.
初始空间文件看起来不错
library("ggplot2")
library("raster")
sd0 <- readShapePoly("./IPUMSI_world.shp")
df0 <- fortify(sd0)
ggplot(data = df0, mapping = aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "black", colour = "black")
Run Code Online (Sandbox Code Playgroud)
当我想专注于拉丁美洲时,我会得到一些不需要的水平线:
ggplot(data = df0, mapping = aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "black", colour = "black") +
coord_map(xlim = c(-125, -30), ylim = c(-60, 35))
Run Code Online (Sandbox Code Playgroud)
我尝试使用该clipPolys功能修复此问题,遵循此处的指导
library("PBSmapping")
df1 <- df0
names(df1)[c(1,2,6,3)] <- c("X","Y","PID","POS")
df1$PID …Run Code Online (Sandbox Code Playgroud) 我正在尝试将Google Trend结果导入R.
我尝试过rGtrends和RGoogleTrends.第一个似乎卡住下载CSV文件:
> require(devtools)
> install_github("rGtrends","emhart")
> library(rGtrends)
> my_terms <- c("Twitter", "Myspace")
> twit_ms <- rGtrends(my_terms)
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:/.../Documents/R/win-library/3.0/rGtrends/src/pyGTrends.py", line 105, in csv
raise Exception("Could not find requested section")
Run Code Online (Sandbox Code Playgroud)
第二个我有登录问题(不知道为什么我需要提供我的谷歌用户名和密码?我可以在我的浏览器中探索谷歌趋势而不这样做.)
我想获得一个DataTable(包括其所有排名,搜索和页面功能),它不会在整个页面中完全展开,并导致每列中有大量的空白区域......

...理想情况下,列宽类似于"包裹"样式renderTable...

我知道我可以修复相对列宽,但是,我的表将根据所选输入的不同数量的列动态更新.我希望其他列扩展到右侧的空白区域,然后如果它变得比浏览器窗口宽度宽,则触发水平滚动条.
上图中表格的可重复示例......
library(shiny)
runApp(list(
ui = navbarPage(
title = 'Tables',
tabPanel('dataTableOutput', dataTableOutput('ex1')),
tabPanel('tableOutput', tableOutput('ex2'))
),
server = function(input, output) {
output$ex1 <- renderDataTable(iris)
output$ex2 <- renderTable(iris)
}
))
Run Code Online (Sandbox Code Playgroud) 我的表格格式与此类似......
我试图从使用R中提取文本和链接
# write the HTML code from R to reproduce
x <- "
<html>
<head>
</head>
<body>
<table>
<tbody>
<tr>
<th>site</th>
<th>country</th>
</tr>
<tr>
<td> <a href='http://www.nbc.com'>NBC</a> <a href='https://www.cnn.com'>CNN</a> <a href='https://www.nytimes.com'>NY Times</a> </td>
<td> US</td>
</tr>
<tr>
<td> <a href='http://www.dw-world.de/'>DW</a> </td>
<td> DE</td>
</tr>
<tr>
<td></td>
<td>FR</td>
</tr>
<tr>
<td> <a href='http://www.bbc.co.uk'>BBC</a> <a href='https://www.itv.co.uk'>ITV</a></td>
<td> UK</td>
</tr>
</tbody>
</table>
</body>
</html>"
write.table(x = x, file = "table.html", quote = FALSE,
col.names = FALSE,
row.names = FALSE)
file.show("table.html")
Run Code Online (Sandbox Code Playgroud)
最终我想要像这样整洁的数据框架......
# …Run Code Online (Sandbox Code Playgroud) 有没有人知道一种整齐/有效的方法来替换数组中的对角元素,类似于diag(x) <- value矩阵的使用?换句话说,这样的事情:
> m<-array(1:27,c(3,3,3))
> for(k in 1:3){
+ diag(m[,,k])<-5
+ }
> m
, , 1
[,1] [,2] [,3]
[1,] 5 4 7
[2,] 2 5 8
[3,] 3 6 5
, , 2
[,1] [,2] [,3]
[1,] 5 13 16
[2,] 11 5 17
[3,] 12 15 5
, , 3
[,1] [,2] [,3]
[1,] 5 22 25
[2,] 20 5 26
[3,] 21 24 5
Run Code Online (Sandbox Code Playgroud)
但没有使用for循环(我的数组非常大,这个操作已经在循环中).
非常感谢.
我是WinBUGS的新手,我无法获得下面的代码.该模型是syntactically correct(它是具有随机效果的分层logit模型),但是当我单击load data出现的错误消息时expected key word structure.那是什么意思?有人可以帮我解决下面的代码吗?我的数据集更大,但为了简化问题,我只在这里工作,n = 2(组数)和k = 5(每组中的主题数).
model{
for(i in 1:n){
for(j in 1:k){
yij[i,j] ~ dbern(p[i,j])
logit(p[i,j]) <- alpha + beta*xij[i,j] + ui[i]
}
ui[i] ~ dnorm(0,tau)
}
alpha ~ dnorm(0,0.001)
beta ~ dnorm(0,0.001)
tau ~ dunif(0,100)
}
Run Code Online (Sandbox Code Playgroud)
有数据:
list(n=2, k=5, yij=structure(.Data=c(1, 1, 1, 1, 1, 0, 0, 0, 0, 0), .Dim=c(2,5)),
xij = c(0.0494063719, -0.078101264, 0.2748560749, 0.1245743393, -2.531242809, .6849338859, 0.5302062384, 0.7828560148, -0.012341452, 0.5128471157),
ui = c(0.5031197054, 0.5031197054, 0.5031197054, 0.5031197054, …Run Code Online (Sandbox Code Playgroud) 我有一个包含多个维度的大型数据集.我正在创建一个数据资源管理器,我相信如果可以通过多个选项卡选择数据,而不是从非常长的侧边栏中选择数据,那么它将更加用户友好.我用最小的工作示例(下面)一直在玩这个概念,但是当我点击View Plot按钮时我无法切换到Plot选项卡.单击"绘图"选项卡后,反应性将起作用,但是当我更新某些选择(例如群集数量)时,它不会做出反应.
library(shiny)
runApp(list(
ui = shinyUI(fluidPage(
headerPanel('Iris k-means clustering'),
mainPanel(
tabsetPanel(
type = "tabs",
tabPanel(title = "Select X",
selectInput('xcol', 'X Variable', names(iris)),
HTML("<div id='linkToY'><FORM><INPUT Type='BUTTON' VALUE='Next'></FORM></div>") ),
tabPanel(title = "Select Y",
selectInput('ycol', 'Y Variable', names(iris), selected=names(iris)[[2]]),
HTML("<div id='linkToClusters'><FORM><INPUT Type='BUTTON' VALUE='Next'></FORM></div>") ),
tabPanel("Select Clusters", numericInput('clusters', 'Cluster count', 3, min = 1, max = 9),
HTML("<div id='linkToPlot'><FORM><INPUT Type='BUTTON' VALUE='View Plot'></FORM></div>"),
HTML("<div id='linkToData'><FORM><INPUT Type='BUTTON' VALUE='View Data'></FORM></div>") ),
tabPanel(title = "Plot", plotOutput('plot1')),
tabPanel(title = "Data",
dataTableOutput(outputId="table"),
HTML("<script>$('#linkToY').click(function() {
tabs = $('.tabbable .nav.nav-tabs li') …Run Code Online (Sandbox Code Playgroud) 我正在尝试从已经运行的数据集中添加年份标题tweenr.以来来自revolutionanalytics.com的示例
library(tidyverse)
library(tweenr)
library(gapminder)
gapminder_edit <- gapminder %>%
arrange(country, year) %>%
select(gdpPercap,lifeExp,year,country, continent, pop) %>%
rename(x=gdpPercap,y=lifeExp,time=year,id=country) %>%
mutate(ease="linear")
gapminder_tween <- tween_elements(gapminder_edit,
"time", "id", "ease", nframes = 150) %>%
mutate(year = round(time), country = .group) %>%
left_join(gapminder, by=c("country","year","continent")) %>%
rename(population = pop.x)
gapminder_tween %>% arrange(country, .frame) %>% head()
# x y time continent population .frame .group year country lifeExp pop.y gdpPercap
# 1 779.4453 28.80100 1952.000 Asia 8425333 0 Afghanistan 1952 Afghanistan 28.801 8425333 779.4453
# 2 …Run Code Online (Sandbox Code Playgroud) 我想在图像上嵌入一条推文。当我使用短代码在博客文章中嵌入推文时,它不会出现在推特样式中
例如,使用简码:
{{< tweet 989470885475008512 >}}
Run Code Online (Sandbox Code Playgroud)
我得到一个输出(我的Blogdown使用学术主题)
而不是这个(如Blogdown 指南所示)...
有没有一种方法可以覆盖此行为,从而获得类似于第二个示例的外观,或者按照开发者指导方针嵌入一条推文(当我粘贴html代码时,其输出类似于上面的第一张图片)。
我正在猜测,但是我认为嵌入式tweet中Twitter样式的丢失限制了将tweet嵌入图像的可能性(它与图像URL一起提供了与第一个示例类似的输出)。
更新
这是浏览器(Firefox)问题(如@hplieninger所建议)。在Chrome中查看页面时,将显示twitter样式。
尝试从ioslides演示文稿更改标题页的默认文本大小但失败:
---
title: "My title is a bit too long to fully fit on the title page. I would really like to alter the font size to provide a better fit. I have limited CSS skills to do so"
author: "My Name"
date: "29 March 2016"
output:
ioslides_presentation:
css: slide.css
---
## R Markdown
This is an R Markdown presentation.
Run Code Online (Sandbox Code Playgroud)
我的style.css文件是:
h1 { font-size: 12px;}
Run Code Online (Sandbox Code Playgroud)
r ×9
ggplot2 ×2
shiny ×2
animation ×1
blogdown ×1
css ×1
datatables ×1
gganimate ×1
gis ×1
html-table ×1
hugo ×1
javascript ×1
knitr ×1
maps ×1
polygon ×1
r-markdown ×1
rstudio ×1
rvest ×1
tween ×1
twitter ×1
web-scraping ×1
winbugs ×1