我有下面的資料框:
d1_7<-structure(list(conm = c("Facebook Inc", "Facebook Inc", "Facebook Inc",
"Facebook Inc", "Facebook Inc", "Facebook Inc", "Facebook Inc",
"Facebook Inc", "Facebook Inc", "Facebook Inc", "Facebook Inc",
"Facebook Inc", "Facebook Inc", "Facebook Inc", "Facebook Inc",
"Facebook Inc", "Facebook Inc", "Facebook Inc", "Facebook Inc",
"Facebook Inc", "Facebook Inc", "Facebook Inc"), datadate = structure(c(14974,
14974, 15339, 15339, 15705, 15705, 16070, 16070, 16435, 16435,
16800, 16800, 17166, 17166, 17531, 17531, 17896, 17896, 18261,
18261, 18627, 18627), label = "Data Date", format.stata = "%td", class = "Date"),
fin_var = c("mkt_val", "sale", "mkt_val", "sale", "mkt_val",
"sale", "mkt_val", "sale", "mkt_val", "sale", "mkt_val",
"sale", "mkt_val", "sale", "mkt_val", "sale", "mkt_val",
"sale", "mkt_val", "sale", "mkt_val", "sale"), fin_value = c(NA,
1974, NA, 3711, 60321.3848471, 5089, 132250.58, 7872, 203944.28,
12466, 293361.98, 17928, 329388.15, 27638, 511910.46, 40653,
378850.1, 55838, 585783.5, 70697, 778779.16, 85965)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -22L))
我想在我的 ggplot 中放入一個 .png ,如:
這是我的代碼:
library(tidyverse)
library(png)
library(ggplot2)
mypng <- readPNG('C:/Users/User/Documents/Avilla ggplot/mark-zuckerberg-celebrity-mask.png')
plot <- ggplot(d1_7, aes(x = datadate, y = fin_value))
geom_col(aes(fill = conm))
facet_wrap(~conm,ncol=1)
theme_minimal()
theme(legend.position = "none")
ylab('Profits in $ million')
xlab('Fiscal Year')
scale_fill_manual(values=c("#5cc9f5"))
plot guides(fill=guide_legend(title="")) annotation_raster(mypng, ymin = 500000,ymax= 600000,xmin = 2014,xmax = 2015)
我相信我無法顯示它,因為xmin并且xmax不能接受日期作為輸入。

uj5u.com熱心網友回復:
我相信我無法顯示它,因為 xmin 和 xmax 不能接受日期作為輸入。
那是不正確的。你只是不傳遞日期。
plot guides(fill=guide_legend(title=""))
annotation_raster(mypng, ymin = 500000,ymax= 600000,
xmin = as.Date("2014-01-01"),xmax = as.Date("2015-01-01"))

uj5u.com熱心網友回復:
指定日期as.Date或將原始值傳遞給 xmin 和 xmax。
# library(tidyverse)
library(png)
library(ggplot2)
mypng <- readPNG('~/Desktop/tt.png')
plot <- ggplot(d1_7, aes(x = datadate, y = fin_value))
geom_col(aes(fill = conm))
facet_wrap(~conm,ncol=1)
theme_minimal()
theme(legend.position = "none")
ylab('Profits in $ million')
xlab('Fiscal Year')
scale_fill_manual(values=c("#5cc9f5"))
plot guides(fill=guide_legend(title="")) annotation_raster(mypng, ymin = 350000,ymax= 800000,xmin = 16000,xmax = 17000)

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/317985.html
上一篇:ShinyR:無法顯示情節
