提问人:anonymous_horse 提问时间:10/14/2023 最后编辑:anonymous_horse 更新时间:10/14/2023 访问量:84
如何在ggplot中重新定位散点图?
How to re-position the scatter plot in ggplot?
问:
这是我目前的情节以及我想要的样子。
原始情节有点符合我的喜好(我当前的情节存在轴标签)。我希望我的绘图和轴线被放大,但绘图的宽度和高度相同(轴标签不存在)。
谢谢!
尝试使用不同的变化作为绘图边距,但对我不起作用
编辑:添加我的代码。具有三列(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 轴是有限的。。
有谁知道我如何延长 x 轴线同时保持原来的断裂?我尝试过使用中断和限制,但这似乎不起作用
答: 暂无答案
评论
ggimage