使用R ggplot2生成LaTeX样式散点图
我想在R中使用ggplot2生成一个Latex图(散点图) 原始图像: 代码:使用R ggplot2生成LaTeX样式散点图,r,ggplot2,R,Ggplot2,我想在R中使用ggplot2生成一个Latex图(散点图) 原始图像: 代码: df一种解决方法是: ggplot(df,aes(x=x,y=y)) + geom_point(col = "blue", size = 5) + theme_minimal() + labs(x="", y="") + annotate(geom = "text", x = 1, y =
df一种解决方法是:
ggplot(df,aes(x=x,y=y)) + geom_point(col = "blue", size = 5) +
theme_minimal() +
labs(x="", y="") +
annotate(geom = "text", x = 1, y = 5, label = "y") +
annotate("text", x = 7, y = 1, label = "x") +
theme(axis.line.y = element_line(arrow = grid::arrow(length = unit(0.4, "cm"))),
axis.line.x = element_line(arrow = grid::arrow(length = unit(0.4, "cm"))))
你可以试试这个,它几乎可以让你一路走到那里:
- 泰晤士报新罗马式脸谱
- 斜体轴标题
- 不规则网格
- 纵横比=1
不足之处:
- “隐形”箭头
- 轴线上方和下方的轴线标记
df您所说的“类乳胶图”是什么意思?您是否只想生成如上所示的绘图?:)是的,我指的是图中以点为方向的图表。我会添加labs(x='',y='')+主题(plot.text=element\u text(family='Computer Modern'))
,前提是你安装了@lvaro字体,我同意。但是你所说的plot.text
是什么意思呢?当我添加您的plot.text…
建议:错误:元素层次结构中未定义主题元素plot.text
抱歉,我的错误。要更改轴标签的字体,它应该是主题(axis.text=element\u text(family='Computer Modern'))
,而要更改附加的“x”和“y”标签的字体,您应该将参数family='Computer Modern'
添加到每个注释(),如果要制作精确副本并在x轴中包含所有数字,应添加scale\u x\u continuous(breaks=1:max(df$x))
@Raj我没有更改数据中的任何内容。我只是策划了它。因此,您的点看起来就是它们应该看起来的样子:)
ggplot(df,aes(x=x,y=y)) + geom_point(col = "blue", size = 5) +
theme_minimal() +
labs(x="", y="") +
annotate(geom = "text", x = 1, y = 5, label = "y") +
annotate("text", x = 7, y = 1, label = "x") +
theme(axis.line.y = element_line(arrow = grid::arrow(length = unit(0.4, "cm"))),
axis.line.x = element_line(arrow = grid::arrow(length = unit(0.4, "cm"))))