R语言 删除ggplot2绘图的轴标签和刻度线
在这篇文章中,我们将讨论如何在R编程语言中的ggplot2中删除轴标签和刻度线。
在ggplot中,可以使用theme()方法删除轴的标签和刻度线。这个方法基本上是用来修改所做绘图的非数据部分。它使绘图具有良好的图形定制外观。theme()方法是用来处理所做绘图的标签、刻度线和文本的。标签和刻度线要与 element_blank() 方法对齐,以便删除它们。
语法:
theme(axis.text.x = , axis.ticks.x = , axis.text.y = , axis.ticks.y = )
参数:
- axis.text.x , axis.text.y =沿轴的刻度线标签
- axis.ticks.x, axis.ticks.y = 沿轴的刻度线标签
# creating data frame
col1 = c(1: 10)
col2 = c(11: 20)
print("X coordinates")
print(col1)
print("Y coordinates")
print(col2)
# plotting the data frame
graph < - ggplot(df, aes(x=col1, y=col2)) +
geom_point()
# removing axes labels and ticks
graph +
theme(axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())
# printing the graph
print(graph)
输出
[1] "X coordinates"
[1] 1 2 3 4 5 6 7 8 9 10
[1] "Y coordinates"
[1] 11 12 13 14 15 16 17 18 19 20
说明: 通过将x轴和y轴的标记和刻度线设置为element_blank()方法,已经从图形中删除。