我正在尝试导入数据(ods文件),我知道如何导入csv,xls等,但我一直都是.我尝试使用"gnumeric"包,但是R告诉我找不到所需的programm'sssconvert'.谁能帮我?
谢谢.
为了能够处理我想要替换:字符串中的第一个匹配项(这是我的标记,语音开始).
text <- c("Mr. Mark Francois (Rayleigh) (Con): If the scheme was so poorly targeted, why were the Government about to roll it out to employees in the Department of Trade and Industry and the Department for Work and Pensions on the very day the Treasury scrapped it? The CBI and the TUC have endorsed the scheme, which has helped 500,000 people and their families to improve their computer skills. When the Chancellor announced the original concession, he …Run Code Online (Sandbox Code Playgroud) 我也发现了类似的答案像这样的问题,但大部分都是使用包rworldmap,ggmap,ggsubplot或geom_subplot2d.例如,在此处或此处查看.
我想知道如何将其他ggplot对象(如条形图)绘制到地图上,这是从shapefile创建的.我正在使用的那个可以在这里下载.
编辑
正如@beetroot正确指出的那样,可以在上面发布的链接下下载的新文件发生了显着变化.因此,调整shapefile等的名称.
library(rgdal)
library(ggplot2)
library(rgeos)
library(maptools)
map.det<- readOGR(dsn="<path to your directory>/swissBOUNDARIES3D100216/swissBOUNDARIES3D/V200/SHAPEFILE_LV03", layer="VECTOR200_KANTONSGEBIET")
map.kt <- map.det[map.det@data$KANTONSNUM=="CH01000000"|map.det@data$KANTONSNUM=="CH19000000",]
#get centroids
map.test.centroids <- gCentroid(map.kt, byid=T)
map.test.centroids <- as.data.frame(map.test.centroids)
map.test.centroids$KANTONSNR <- row.names(map.test.centroids)
#create df for ggplot
kt_geom <- fortify(map.kt, region="KANTONSNUM")
#Plot map
map.test <- ggplot(NULL)+
geom_polygon(data=kt_geom, aes(long, lat, group=group), fill="white")+
coord_fixed()+
geom_path(data=kt_geom, color="gray48", mapping=aes(long, lat, group=group), size=0.2)+
geom_point(data=map.test.centroids, aes(x=x, y=y), size=9, alpha=6/10)
mapp
Run Code Online (Sandbox Code Playgroud)
但是,我在组合两个地图时遇到了困难map.test,例如地图,例如,这个:
geo_data <- …Run Code Online (Sandbox Code Playgroud) 我对R还是比较新的,希望你能再次帮助我.我有一个长度为42000的字符向量.向量看起来像这样:
a <- c("blablabla-19960101T000000Z-1.tsv", "blablabla-19960101T000000Z-2.tsv", "blablabla-19960101T000000Z-3.tsv")
Run Code Online (Sandbox Code Playgroud)
我想将矢量分割成一个如下所示的数据框:
Name Date no
blablabla 1996-01-01 1
blablabla 1996-01-01 2
blablabla 1996-01-01 3
Run Code Online (Sandbox Code Playgroud)
我正在努力分裂和创建我的数据框.有人可以帮我弄这个吗?谢谢!
我读过我通过伟大的教程在这里。但是,我对jQuery的了解为零。我在ShinyApp中使用了几个tabPanels来显示我的数据。本教程说明了如何跟踪链接单击事件(效果很好,我在本教程中介绍了一个.js)。有没有一种方法可以跟踪用户是否单击了特定的tabPanel(例如Panel1和Panel2)?我尝试使用指向外部资源的链接进行相同的操作,但这不起作用。
tabsetPanel(
tabPanel("Panel1", showOutput("PlotPanel1", 'dimple')),
tabPanel("Panel2", showOutput("PlotPanel2", 'dimple')))
Run Code Online (Sandbox Code Playgroud)
编辑:
我想我必须在我的analytics.js文件中包含一些代码。因此,我尝试了几件事,但是坦率地说,由于不了解jQuery,这是错误的。有人可以帮忙吗?
$( ".selector" ).tabs({
on('option', 'click', function(l) {
ga('send', 'event', 'tabPanel', 'tabPanel', $(l.currentTarget).val());
}
});
Run Code Online (Sandbox Code Playgroud)
谢谢。
我知道这个问题已在其他地方得到解答.我试图按照@jlhoward的指示,但显然我的技能太有限了.我可以再问你的帮助,R社区吗?
这就是我所拥有的:
瑞士的shapefile:链接
以及相应的CSV文件,用于市政名称及其邮政编码:链接
数据网站:cadastre.ch
关于最后一次流行投票的其他数据:直接链接,excel文件
我通过合并在CSV文件(wow.csv)(我要说明的数据)中添加了一列.该文件现在看起来像这样:
Gemeinden code Ja.Anteil Ortschaft PLZ Zusatzziffer Kantonskürzel E N
1 Aadorf 4551 78.78638 Aawangen 8522 2 TG 710206 263564
2 Aadorf 4551 78.78638 Ettenhausen TG 8356 0 TG 710129 259411
3 Aadorf 4551 78.78638 Aadorf 8355 0 TG 710588 261648
4 Aadorf 4551 78.78638 Guntershausen 8357 0 TG 711741 258934
5 Aadorf 4551 78.78638 Wittenwil 9547 0 TG 712002 262572
Run Code Online (Sandbox Code Playgroud)
之后我试着按照@jlhoward的说明:
muni多边形转换为数据框以进行绘图我让自己熟悉Shiny,然而,熟悉可能有点夸大其词......我尝试了Shiny Tutorials,特别是我想为自己的数据调整第5课.
我help.R在教程中创建了一个额外的R-Script :
percent_map <- function(var, color, legend, min = 0, max = 100) {
# constrain gradient to percents that occur between min and max
var <- pmax(var, min)
var <- pmin(var, max)
#plot
aha <- ggplot(abst, aes(long,lat, group=group))+
geom_polygon(aes(fill=var))+
coord_fixed()+
scale_fill_gradient(low = "lightskyblue", high = color,
space = "Lab", na.value = "lightblue")+
labs(title=var, x="", y="")+
theme(axis.text=element_blank(),
axis.ticks=element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank()
)
print(aha)
}
Run Code Online (Sandbox Code Playgroud)
我的ui.R:
library(shiny)
# …Run Code Online (Sandbox Code Playgroud) 我有两张图像,我想剪出一个圆圈并将该图像放在另一张图像之上。然而,我很难实现这一目标。这里,两个输入图像和所需的输出:
这是我的尝试:
library(magick)
library(dplyr)
p1 <- image_read("https://i.stack.imgur.com/uLypl.jpg")
p2 <- image_read("https://i.stack.imgur.com/bkd1M.jpg")
# Inspect
# p1 |> image_scale("20%")
# p2 |> image_scale("20%")
ii <- magick::image_info(p1)
factx <- 5.48
facty <- 3.95
im1 <- image_crop(p2, geometry=paste0(ii$width/factx, "x", ii$height/facty, "+0+0"),
gravity="center")
# Inspect
# im1 |> image_scale("20%")
fig <- image_draw(image_blank(ii$width/factx, ii$width/factx))
symbols(ii$width/factx/2, ii$width/factx/2, circles=(ii$width/factx/2), bg='black', inches=FALSE, add=TRUE)
dev.off()
im2 <- image_composite(im1, fig, operator='minus')#
# image_background(im2, 'white') |> image_scale("20%")
im3 <- image_background(im2, 'white')
# Inspect
image_composite(p1, im3, gravity="center")|> image_scale("20%")
Run Code Online (Sandbox Code Playgroud)
然而,这导致了不希望的结果。该点不是蓝色而是黑色,并且圆圈周围似乎有一个正方形:

谢谢你的帮助!
我尝试构建一个闪亮的应用程序.我想从头开始,因此开始非常基本.现在,当我试图运行我的应用程序时,起初它似乎工作,但立即应用程序冻结并出现此错误:
Error in handlers$add(handler, key, tail) : Key / already in use
Run Code Online (Sandbox Code Playgroud)
我认为我做错了,所以用闪亮的教程中的一个例子试了一下.但是,同样的错误.
这是我的文件:
ui.R
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
titlePanel("Test"),
sidebarLayout(
sidebarPanel("sidebar panel"),
mainPanel("Data")
)
))
Run Code Online (Sandbox Code Playgroud)
server.R
setwd("/home/User")
library(shiny)
shinyServer(
function(input, output) {
})
Run Code Online (Sandbox Code Playgroud)
随着runApp("ws")我得到错误.
感谢任何帮助,thx.
我试图将每组的每个蓝点与其相应的红点连接起来。但是,我在使用时遇到了麻烦geom_segment。谢谢帮助。
repl <- data.frame(title = c("A", "B", "C", "A", "B", "C"), diff = c(10.06, -1.89, 12.79, 10.06, -1.89, 12.79), id = c(1:6), acc= c(43, 50, 44, 43, 50, 44), variable= c(rep("A", 3), rep("B", 3)), value=c(43,50,44,53,48,56))
ggplot(repl, aes(value, title, y=reorder(title, diff), group=variable, color=variable)) +
geom_point(size=2, shape=8)+
geom_segment(aes(xend=value, x=value, y=title, yend=title), col='gray')
Run Code Online (Sandbox Code Playgroud)
对于每个组,应该有一条线连接水平线上的两个点,我应该怎么做?
我只是在学习如何处理model.matrix. 例如,为了创建样本外预测,我从我的模型中提取公式,假设它是一个线性模型。使用该函数formula(mymodel)提取:
form <- formula(y ~ x1 + x2 * x3)
Run Code Online (Sandbox Code Playgroud)
现在,要创建预测,我需要一个没有我的y. 我可以手动输入:
X <- model.matrix(~ x1 + x2 * x3, data=out.of.sample.data)
Run Code Online (Sandbox Code Playgroud)
但是,有没有办法使用,例如,update摆脱我的公式的左侧部分?
谢谢!