【问题标题】:Bubble plot of mine quakes [closed]矿井地震的气泡图[关闭]
【发布时间】:2013-12-27 06:46:40
【问题描述】:

在 R 中,我希望创建一个类似于下面的热图。其中大小代表排出的能量,颜色代表深度。

我的数据集 (CSV) 如下所示:

X,       Y,      Z,     E
19305,  -11211,  -599,  3000
22159,  -13553,  -600,  300
22155,  -13519,  -823,  2000
...     ...      ...    ...

其中 X、Y 和 Z 是轴,E 是能量。

过去几个小时我一直在玩 R,但无法完成我的目标。如果可能,请提供示例代码。

Related

谢谢!

【问题讨论】:

标签: r plot bubble-chart


【解决方案1】:

编辑:已更新以使用更有意义的数据。原始响应位于底部。

这张地图...

...可以使用以下代码生成:

library(ggplot2)
library(maptools)

# grab earthquake data [source: USGS Earthquake Hazards Program]
url <- "http://comcat.cr.usgs.gov/fdsnws/event/1/query"
querystring <- "starttime=2012-01-01T00:00:00Z"
querystring <- paste(querystring,"minmagnitude=6", sep="&")   # magnitude >= 6
querystring <- paste(querystring,"mindepth=0",     sep="&")
querystring <- paste(querystring,"maxdepth=1000",  sep="&")   # depth <= 1000 km
querystring <- paste(querystring,"format=csv",     sep="&")   # return CSV file
uri <- paste(url,querystring,sep="?")
ggQuakes <- read.table(header=T,sep=",", file=uri)
# grab world map [built into maptools package]
ggMap  <- fortify(wrld_simpl)
# create map payers
ggp <- ggplot(ggQuakes)
ggp <- ggp + geom_point(aes(x=longitude ,y=latitude ,color=depth ,size=mag), alpha=0.8)
ggp <- ggp + scale_size(range=c(4,8))
ggp <- ggp + scale_color_gradient(low="#aaaaaa", high="#cc0000")
ggp <- ggp + geom_path(data=ggMap, aes(x=long, y=lat, group=group))
ggp <- ggp + coord_equal()
ggp <- ggp + theme(legend.position="bottom")
# render map
print(ggp)

原始回复:

如果您提供更具代表性的样本数据会更好,但调用您的数据集gg

library(ggplot)
ggplot(gg) + 
  geom_point(aes(x=X,y=Y,color=Z,size=log(E)), alpha=0.5) +
  scale_size(range=c(4,8)) +        # sets minimum and maximum size
  scale_color_gradient(low="#aaaaaa", high="#cc0000")

我使用了对数(能量)标度,因为水平非常不同。

【讨论】:

  • 感谢 jlhoward!我还在下面发布了我自己的解决方案。 DWin 为我指明了正确的方向。
  • @bskool - 见上面的编辑。
【解决方案2】:
symbols(quakes$X, quakes$Y, circles=quakes$E)

radius <- sqrt( quakes$E/ pi )
symbols(quakes$X, quakes$Y, circles=radius)

symbols(quakes$X, quakes$Y, circles=radius, inches=0.35, fg="white", bg="red", xlab="Murder Rate", ylab="Burglary Rate")

只是缺少 Z 着色。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    相关资源
    最近更新 更多