小编doo*_*ote的帖子

有没有办法为ggmap添加比例尺(线性距离)?

并不是说这对我的问题至关重要,但这是我的情节示例,我想在其上添加一个比例尺.

ggmap(get_map(location = "Kinston, NC", zoom = 12, maptype = 'hybrid')) +
geom_point(x = -77.61198, y = 35.227792, colour = "red", size = 5) +
geom_point(x = -77.57306, y = 35.30288, colour = "blue", size = 3) +
geom_point(x = -77.543, y = 35.196, colour = "blue", size = 3) +
geom_text(x = -77.575, y = 35.297, label = "CRONOS Data") +
geom_text(x = -77.54, y = 35.19, label = "NOAA") +
geom_text(x = -77.61, y = 35.22, label = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 ggmap

17
推荐指数
2
解决办法
3916
查看次数

如何反转轴顺序并在ggplot中使用预定义的比例?

我读过过去后询问使用scale_reverse,并scale_log10在同一时间.我有一个类似的问题,除了我的规模,我试图"反向"是"鳞片"包中的预定义比例.这是我的代码:

    ##Defining y-breaks for probability scale
    ybreaks <- c(1,2,5,10,20,30,40,50,60,70,80,90,95,98,99)/100

    #Random numbers, and their corresponding weibull probability valeus (which I'm trying to plot)
    x <- c(.3637, .1145, .8387, .9521, .330, .375, .139, .662, .824, .899)
    p <- c(.647, .941, .255, .059, .745, .549, .853, .451, .352, .157)
    df <- data.frame(x, p)

    require(scales)
    require(ggplot2)

    ggplot(df)+
        geom_point(aes(x=x, y=p, size=2))+
        stat_smooth(method="lm", se=FALSE, linetype="dashed", aes(x=x, y=p))+
        scale_x_continuous(trans='probit',
                           breaks=ybreaks,
                           minor_breaks=qnorm(ybreaks))+
        scale_y_log10()
Run Code Online (Sandbox Code Playgroud)

结果情节: 情节 有关更多信息,我想要达到的尺度是概率绘图比例,它在比例的任一端(0和1)具有更精细的分辨率以显示极端事件,对中值的分辨率不断降低(0.5 ).

我希望能够scale_x_reverse同时使用我的scale_x_continuous概率范围,但我不知道如何在任何自定义范围内构建它.对此有何指导?

r ggplot2

6
推荐指数
1
解决办法
1859
查看次数

由于地理单位不同,我无法在我的ggmap中添加shapefile

我正在尝试将ESRI shapefile(.shp)添加到北卡罗来纳州的ggmap图中,其中包含以下代码:

x <- get_map(location="North Carolina", zoom=6, maptype="terrain")

ggmap(x) + geom_polygon(data=citylim83.df, aes(x=long, y=lat), fill="red", alpha=0.2)

我加载并强化的shapefile citylim83.df 没有出现.以下是用于将shapefile加载到ggplot的代码:

    epsgs <- make_EPSG()
    citylim <- readOGR(dsn=".", layer="MunicipalBoundaries_polys")`
Run Code Online (Sandbox Code Playgroud)

在对EPSG进行搜索之后,MunicipalBoundaries投影的单位是国家 - 平面系统的ft-US.即使这个.shp的地理坐标系为NAD83,我也想把它投射到NAD83以摆脱状态平面系统(NAD83的EPSG代码(UTM-17N)是26917):

    citylim83 <- spTransform(citylim, CRS("+init=epsg:26917"))
    summary(citylim83)

    Object of class SpatialPolygonsDataFrame
    Is projected: TRUE 
    [+init=epsg:26917 +proj=utm +zone=17 +ellps=GRS80 +datum=NAD83 +units=m

    citylim83.df <- fortify(citylim83)
Run Code Online (Sandbox Code Playgroud)

然后在上面显示的ggmap代码中使用该数据帧.

即使它现在已经被投射到NAD83中,它仍然不会出现在基础ggmap上.我导入的get_map对象的基本投影是什么?是否有命令找到这个,所以我可以将我的地图与我想要显示在其上的shapefile匹配?我是否必须"取消"我的citylim对象?仅供参考,如果不清楚,shapefile是北卡罗来纳州每个城市的城市限制边界.任何帮助都会非常感激,因为我对ggplot2/ggmap社区很新.

gis r ggplot2 ggmap

4
推荐指数
1
解决办法
2855
查看次数

在ggplot中接受"Date"类的水平和垂直线有问题吗?

我正在尝试根据用户Didzis Elferts提供的慷慨代码在ggplot中制作甘特图.我正在尝试添加一条显示今天日期的垂直线,但是包中的geom_vline图层ggplot2只是返回Error: Discrete value supplied to continuous scale.这是我的代码:

    today <- as.Date(Sys.Date(), "%m/%d/%Y")
    library(scales)
    ggplot(mdfr, aes(time,name, colour = is.critical)) + 
      geom_line(size = 6) +
      xlab("") + ylab("")+
      labs(title="Sample Project Progress")+
      theme_bw()+
      scale_x_datetime(breaks=date_breaks("1 year"))+
      geom_vline(aes(xintercept=today))
Run Code Online (Sandbox Code Playgroud)

没有geom_vline命令的情节看起来像这样情节:

任何理由geom_vline不适用于"日期"字符?

编辑:用于生成绘图的可重现代码:

    ### GANTT CHART 1 ###############3
    tasks <- c("Meetings", "Client Calls", "Design", "Bidding", "Construction")
    dfr <- data.frame(
      name        = factor(tasks, levels = tasks),
      start.date  = c("07/08/2013", "07/08/2013", "07/23/2013", "08/30/2013", "9/30/2013"),
      end.date    = c("07/12/2013", "07/13/2013", …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

3
推荐指数
1
解决办法
2092
查看次数

标签 统计

ggplot2 ×4

r ×4

ggmap ×2

gis ×1