如何在ggplot中重新定位散点图?

How to re-position the scatter plot in ggplot?

提问人:anonymous_horse 提问时间:10/14/2023 最后编辑:anonymous_horse 更新时间:10/14/2023 访问量:84

问:

这是我image目前的情节以及我想要的样子。

原始情节有点符合我的喜好(我当前的情节存在轴标签)。我希望我的绘图和轴线被放大,但绘图的宽度和高度相同(轴标签不存在)。

谢谢!

尝试使用不同的变化作为绘图边距,但对我不起作用

编辑:添加我的代码。具有三列(VA、VF、image_link)的基本 df。将图像绘制为散点。

plot <- ggplot(df_noemp, aes(x = VA, y = VF, image = image_link)) +
  geom_image(aes(image = image_link), size = 0.05, by = "height", asp = 1.33) + 
  labs(
    x = paste0("<br><br><span style='font-size: 14pt'>abcd</span><br><span style='font-size: 11pt'>abcd</span>"),
    y = paste0("<span style='font-size: 14pt'>abcd</span><br><span style='font-size: 11pt'>abcd</span><br>"),
    title = paste0("<br><span style='font-size: 17pt'>abcd</span><br><span style='font-size: 9pt'>abcd</span><br><br><br>")) +
  scale_y_continuous(labels = function(x) paste0(x, "%"))+
  coord_cartesian(ylim=c(-150, 60))+
  scale_x_continuous(labels = function(x) paste0(x, "%"))+
  coord_cartesian(xlim=c(-70, 70)) +
  theme(
    panel.grid.minor = element_blank(),
    panel.grid.major = element_line(linetype = "dashed", color = "#fafafa"),
    axis.text.x = element_text(color = "#2e2e2e", size = 10.9, family = "Tw Cen MT"),
    axis.text.y = element_text(color = "#2e2e2e", size = 10.9, family = "Tw Cen MT"),
    axis.title = element_blank(),
    plot.title = ggtext::element_markdown(angle = 0, face = "bold", family = "Trebuchet MS"),
    plot.caption = ggtext::element_markdown(margin = margin(t = 20), size = 6, family = "Trebuchet MS"),
    plot.background = element_rect(color = NA, fill = "#f5f5f5"),
    axis.line.x = element_line(color="#2e2e2e", size = 0.6),
    axis.line.y = element_line(color="#2e2e2e", size = 0.6),
    axis.title.x = ggtext::element_markdown(angle = 0, face = "bold", family = "Tw Cen MT"),
    axis.title.y = ggtext::element_markdown(angle = 90, face = "bold", family = "Tw Cen MT"),
    aspect.ratio = 1/1.33
  )  


ggsave(
  "var-asp-theme.png", plot, 
  # make the width equivalent to the aspect.ratio
  height = 9, width = 8, dpi = "retina"
)
DF looks like this

VA   VF   image_link
1    2    path_one
2    4    path_two
and so on

编辑2:不知何故,我自己偶然发现了答案,但又出现了另一个问题。首先,只是为plot_margin使用了更多的变体,并偶然发现了正确的变体。但是我的 x 轴是有限的。image

有谁知道我如何延长 x 轴线同时保持原来的断裂?我尝试过使用中断和限制,但这似乎不起作用

R ggPlot2 可视化 散点图

评论

3赞 r2evans 10/14/2023
请提供用于生成该图的代码。我认识到你正在空白内容;您可以使用假数据来在一定程度上代表您的真实数据,以便可以共享您的绘图代码。谢谢!
0赞 anonymous_horse 10/14/2023
@r2evans 嘿,对不起,刚刚添加了代码。如前所述,没有什么太特别的df。只有三列,其中一列有图像链接,我将将其用作散点。
0赞 r2evans 10/14/2023
我也在假设ggimage
0赞 anonymous_horse 10/14/2023
是的,这里使用了 ggimage
0赞 anonymous_horse 10/14/2023
嘿,@r2evans,我不知何故得到了我最初问题的答案,但遇到了一个新问题。希望你能调查一下,也许你能在这里帮助我。谢谢!

答: 暂无答案