Bubble plot of mine quakes [closed]

风格不统一 提交于 2019-12-13 09:45:20

问题


In R I am looking to create a heatmap similar to the one below. Where size represents energy expelled and color represents depth.

My dataset (CSV) looks something like this:

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

Where X, Y & Z are axes and E is energy.

I have spent the past couple hours playing with R but unable to accomplish what I have set out to. Please provide sample code if possible.

Related

Thanks!


回答1:


Edit: Updated to use more meaningful data. The original response is at the bottom.

This map...

... can be produced with the following code:

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)

Original Response:

It would be better if you provided more representative sample data, but calling your dataset 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")

I used a log (Energy) scale because the levels are so different.




回答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")

Just missing Z colorizing.



来源:https://stackoverflow.com/questions/20482822/bubble-plot-of-mine-quakes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!