在 D3.js 中,似乎在其他对象之前绘制的对象然后隐藏它们对鼠标悬停侦听器变得不可见。有解决方法吗?
请参阅此工作示例。
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<script type="text/javascript" src="scripts/d3.v3.js"></script>
</head>
<body>
<div id="viz"></div>
<script type="text/javascript">
d3.select("body").style("background-color", "black");
var sampleSVG = d3.select("#viz")
.append("svg")
.attr("width", 400)
.attr("height", 200);
sampleSVG.append("circle")
.style("fill", "grey")
.style("stroke-width", 2)
.attr("r", 60)
.attr("cx", 150)
.attr("cy", 100)
.on("mouseover", function(){d3.select(this).style("fill", "red");})
.on("mouseout", function(){d3.select(this).style("fill", "grey");});
sampleSVG.append("circle")
.style("stroke", "yellow")
.style("opacity", 0.5)
.style("stroke-width", 2)
.attr("r", 100)
.attr("cx", 250)
.attr("cy", 100)
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 有谁知道它是否可以用ggplot映射到六边形大小?大小在geom_hex文档中列为参数,但stat_hexbin中没有大小映射的示例,因此这似乎与bin大小有关.
举个例子:
ggplot(economics, aes(x=uempmed, y=unemploy)) + geom_hex()
Run Code Online (Sandbox Code Playgroud)

但是查看人口分布(如下),将分箱平均人口映射到六边形大小可能是有用的,但我没有找到这个的公式(如果存在).
ggplot(economics, aes(x=uempmed, y=unemploy, col=pop)) + geom_point()
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?
我似乎无法复制添加线性abline到log-log ggplot.下面的代码说明.感谢我出错的想法.
d = data.frame(x = 100*sort(rlnorm(100)), y = 100*sort(rlnorm(100)))
(fit = lm(d$y ~ d$x))
# linear plot to check fit
ggplot(d, aes(x, y)) + geom_point() + geom_abline(intercept = coef(fit)[1], slope = coef(fit)[2], col='red')
# log-log base plot to replicate in ggplot (don't worry if fit line looks a bit off)
plot(d$x, d$y, log='xy')
abline(fit, col='red', untf=TRUE)
# log-log ggplot
ggplot(d, aes(x, y)) + geom_point() +
geom_abline(intercept = coef(fit)[1], slope = coef(fit)[2], col='red') +
scale_y_log10() + scale_x_log10()
Run Code Online (Sandbox Code Playgroud) 基于 ggplot2 的密封示例,我尝试更改箭头的粗细,以便它们的整体大小更好地反映数据变量。我可以指定长度和厚度,但不知道如何更改箭头的大小。非常感谢任何建议。
require(ggplot2)
require(grid)
d = seals[sample(1:nrow(seals), 100),]
d$size = sqrt(sqrt(d$delta_long^2 + d$delta_lat^2))
ggplot(d, aes(x = long, y = lat, size = size)) +
geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat), arrow = arrow(length = unit(0.1,"cm")))
Run Code Online (Sandbox Code Playgroud)

编辑
解决方案代码:
ggplot(d, aes(x = long, y = lat, size = size)) +
geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat),
arrow = arrow(length = unit(d$size/3, "cm"), type='closed')) +
scale_size(range = c(0, 2))
Run Code Online (Sandbox Code Playgroud) 在与R等效的R包中是否存在CMY颜色功能rgb()?{base}或{colourSpace}中似乎什么都没有。我有一个自定义函数,可以在此处发布,但最好使用本机函数。
我曾尝试在/ etc/crontab和crontab -e上通过SSH添加cronjobs.似乎都没有人工作!
我需要根据单独的种群网格数据集计算一组空间区域的质心.感谢如何在下面的例子中实现这一目标.
提前致谢.
require(raster)
require(spdep)
require(maptools)
dat <- raster(volcano) # simulated population data
polys <- readShapePoly(system.file("etc/shapes/columbus.shp",package="spdep")[1])
# set consistent coordinate ref. systems and bounding boxes
proj4string(dat) <- proj4string(polys) <- CRS("+proj=longlat +datum=NAD27")
extent(dat) <- extent(polys)
# illustration plot
plot(dat, asp = TRUE)
plot(polys, add = TRUE)
Run Code Online (Sandbox Code Playgroud)

我如何定位selectInput()除了标题之外的Shiny小部件(例如下拉框)?我一直在玩各种tags配方而没有任何运气.感谢任何指针.
ui.R
library(shiny)
pageWithSidebar(
headerPanel("side-by-side"),
sidebarPanel(
tags$head(
tags$style(type="text/css", ".control-label {display: inline-block;}"),
tags$style(type="text/css", "#options { display: inline-block; }"),
tags$style(type="text/css", "select { display: inline-block; }")
),
selectInput(inputId = "options", label = "dropdown dox:",
choices = list(a = 0, b = 1))
),
mainPanel(
h3("bla bla")
)
)
Run Code Online (Sandbox Code Playgroud)
server.R
shinyServer(function(input, output) { NULL })
Run Code Online (Sandbox Code Playgroud) 我很难让ggplot绘制具有孔的多边形。以下说明。首先使用获取shapefile git clone https://github.com/geotheory/volcano。下一个:
require(ggplot2); require(ggmap); require(dplyr); require(maptools)
v = readShapePoly('volcano/volcano.shp')
v@proj4string = CRS('+proj=longlat +datum=WGS84')
# confirm polygons spatially exclusive (don't overlap)
plot(t(bbox(v)), type='l', lwd=8)
plot(v, col=paste0(colorRampPalette(c('grey','red'))(8),'dd'), add=T)
Run Code Online (Sandbox Code Playgroud)
看起来还可以 一dd,如果由多个多边形挡住阿尔法应该呈现的线不可见。现在让我们尝试ggplot。
d = fortify(v) %>% as_data_frame()
bb = bbox(v)
toner = get_stamenmap(c(bb[1,1], bb[2,1], bb[1,2], bb[2,2]), zoom=11, maptype='toner')
ggmap(toner) + geom_polygon(data=d, aes(long, lat, group=group, fill=id), alpha=.5)
Run Code Online (Sandbox Code Playgroud)
中心多边形必须重叠,因为基础地图在中心完全被遮盖了。让我们检查漏洞的强化数据:
d %>% select(id, hole) %>% table()
hole
id FALSE TRUE
0 278 0
1 715 0
2 392 388
3 388 331 …Run Code Online (Sandbox Code Playgroud) 有谁知道如何设置 Shiny Leaflet 地图的默认渲染缩放,以便完整的世界地图缩放以适合窗口宽度(即 -180° 到 180° 适合窗口)?我只能将缩放设置为整数,2太小和3太大。可重现的例子:
require(shiny)
require(leaflet)
require(magrittr)
d = data.frame(country = c('China', 'Brazil', 'Canada'), lon = c(105, -52, -95), lat = c(35, -10, 60))
server <- function(input, output, session) {
output$mymap <- renderLeaflet({
leaflet(d) %>%
addCircleMarkers(layerId = ~country, lng = ~lon, lat = ~lat, label = ~ country, radius=30) %>%
addProviderTiles(providers$Stamen.TonerLite, options = providerTileOptions(noWrap = TRUE, minZoom=1, maxZoom=18)
)
})
}
ui <- fluidPage(
tags$head(tags$style(HTML("#mymap { position: fixed; left: 0; top: 0; …Run Code Online (Sandbox Code Playgroud)