我正在嘗試使用 annotation_raster 將影像放在時間序列圖上,但因為 y 值是我不斷收到錯誤的日期“
“UseMethod(“rescale”)中的錯誤:沒有適用于“rescale”的適用方法應用于“character”類的物件
有沒有辦法使用 annotation_raster 或另一種方法更好?
require(ggplot2)
require(ggpubr)
library(png)
###Set working directory
wd <- "E:/R/DataViz/Data" # top level working directory
setwd(wd)
###Make Data Frame
Dates <- seq(as.Date('2020-01-01'), as.Date('2020-01-31'), by = 'days')
Number <- seq(1:31)
DF <- data.frame(Dates,Number)
###Import PNG
mypngfile <- download.file('http://api.altmetric.com/donut/502878_64x64.png', destfile = 'mypng.png', mode = 'wb')
PNG <- readPNG("mypng.png")
####Plot Data
ggplot(DF,aes(x = Dates, y = Number))
geom_line()
annotation_raster(PNG, ymin = 20,ymax = 30,
xmin =
"2020-01-06",
xmax =
"2020-01-27")
uj5u.com熱心網友回復:
由于您的x值是日期值,因此您需要xmin/xmin在呼叫中使用 Dates annotation_raster。采用
ggplot(DF,aes(x = Dates, y = Number))
geom_line()
annotation_raster(PNG, ymin = 20,ymax = 30,
xmin =
as.Date("2020-01-06"),
xmax =
as.Date("2020-01-27"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/427655.html
