在 R markdown 中并排绘制图像和绘图

Image and plotly plot side by side in R markdown

我正在尝试在 R markdown 中并排显示图像和绘图(plotly gauge),但是图像只显示空白图表。我已将图像导入 plotly 并尝试使用 subplot 并排显示它们。有什么关于我遗漏的建议吗?


# Photo
photo <- plot_ly(domain = list(x = c(0, 0.5), y = c(0, 1)))%>%
  layout(
    images = list(source =  "C:/Users/Name/Documents//Image.PNG"
      ))

# Gauge value
x <- mean(df$variable)

# Plot
fig1 <- plot_ly(
  value = x,
  number = list(suffix = "%"),
  title = list(text = "Title"),
  type = "indicator",
  mode = "gauge+number",
  gauge = list(
    axis =list(range = list(NULL, 100)),
    steps = list(
      list(range = c(0, 78), color = "white"),
      list(range = c(78, 88), color = "green"),
      list(range = c(88, 100), color = "white")),
    bar = list(color = "black")),
  domain = list(x = c(0.5, 1), y = c(0, 1)))

subplot(photo, add_trace(fig1))

我没有在 RMarkdown 中尝试过,但我会尝试这个:

library(plotly)
library(EBImage) # BiocManager::install("EBImage")

p1 <- plot_ly(economics, x = ~pop)

img <- readImage("mobiussolid.png")
p2 <- plot_ly(type = "image", z = img*255) %>% 
  layout(margin=list(l=10, r=10, b=0, t=0),
         xaxis=list(showticklabels=FALSE, ticks=""),
         yaxis=list(showticklabels=FALSE, ticks=""))

subplot(p1, p2)