2017-10-26 3 views
0

私は、x軸の日付とy軸の連続点を持つ散布図を作成しました。ggplot annotation_custom画像が正しいY軸にプロットされていません

特定の日付では、その日付の月の画像をプロットしたいと思いますが、画像はy軸上に正しくプロットされていないようです。

私は296ピクセル幅の高さで、高さを設定するためにx/y最小値と最大値を使用しようとしています。

編集 - ここでは画像 enter image description here

library(ggplot2) 
library(dplyr) 


rm(list = ls()) 

startDate <- as.Date("2016-01-01") 
endDate <- as.Date("2017-01-01") 

testData <- data.frame(dater = seq(startDate, endDate, by = "day"), 
         score = rnorm(367, 50, 10) 
) 


imgP <- filter(testData, dater %in% as.Date(c("2016-04-01"))) 

gTest <- ggplot(testData, aes(x=dater, y=score)) + 
      geom_point() + scale_y_continuous(breaks = seq(20, 70, 5)) 


img1 <- readPNG("G:/MHOShare/MHO Staff/James Holland/TempDump/themoon.png") 
g1 <- rasterGrob(img1, interpolate=TRUE) 

gTest + annotation_custom(g1, xmin = imgP$dater, 
          xmax = imgP$dater + 10, 
          ymin = 50, 
          ymax = 55) 

がある。これは、このイメージを生成するが、画像のないコーナーが50または55であると思わないそれは、これら2つの値の間で画像を表示しているようです。私はgrobがそのエリア全体を埋めると予想されているので、それはそれを中心にしていると思う。 pngはそのスペースよりもはるかに広いはずです。

小さい画像を使用する必要がありますか?

enter image description here

+0

あなたは 'themoon.png'を共有でした:これは私が別のthemoon.png画像を使用して取得した結果でしょうか? –

答えて

0

あなたのコードは私のR 3.4.2で正常に動作します。

library(ggplot2) 
library(dplyr) 
library(png) 
library(grid) 
library(RCurl) 

startDate <- as.Date("2016-01-01") 
endDate <- as.Date("2017-01-01") 
testData <- data.frame(dater = seq(startDate, endDate, by = "day"), 
         score = rnorm(367, 50, 10) 
) 

imgP <- filter(testData, dater %in% as.Date(c("2016-04-01"))) 
gTest <- ggplot(testData, aes(x=dater, y=score)) + 
      geom_point() + scale_y_continuous(breaks = seq(20, 70, 5)) 

img1 <- readPNG(getURLContent("http://www.dunakin.com/projects/solarsystem/images/TheMoon.png")) 
g1 <- rasterGrob(img1, interpolate=TRUE) 

gTest + annotation_custom(g1, xmin = imgP$dater, xmax = imgP$dater + 10, ymin = 50, ymax = 55) 

enter image description here

関連する問題