ggplot2 删除轴标签

ggplot2 remove axis label

我有以下数据集:

dput(head(active_clients))
structure(list(Date = structure(c(1422662400, 1425081600, 1427760000, 
1430352000, 1433030400, 1435622400), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), value = c(65139, 66615, 66669, 67081, 67277, 
67366), month = 1:6, year = c(2015L, 2015L, 2015L, 2015L, 2015L, 
2015L), year_month = c("1/15", "2/15", "3/15", "4/15", "5/15", 
"6/15"), year2 = c("15", "15", "15", "15", "15", "15")), .Names = c("Date", 
"value", "month", "year", "year_month", "year2"), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"))

我正在使用 ggplot2 绘制以下 line/point 图表。

t <- ggplot(active_clients)  +
  geom_point(aes(as.factor(year_month), 
                 value), 
             size = 2, 
             color="deepskyblue4") +
  geom_line(aes(as.factor(year_month), 
                value,
                group = 1, alpha = 0.5), 
            color = "deepskyblue4") +

  xlab("") + 
  ylab("") +
  theme(legend.title = element_blank()) +
  theme_minimal()

ggplotly(t)

但我无法从 x 轴上删除标签。

我也试过添加:

theme(legend.title = element_blank(), axis.text = element_blank())

不确定我做错了什么。

有什么提示吗?

更新

这是我得到的情节:

要删除 x 轴标签,您应该尝试在 theme()

中使用 axis.text.x=element_blank()

删除 x 轴标签:

ggplot(active_clients)  +
  geom_point(aes(as.factor(year_month), value), size = 2, color="deepskyblue4") +
  geom_line(aes(as.factor(year_month), value, group = 1, alpha = 0.5), color = "deepskyblue4") +
  theme_minimal()+
  theme(axis.text.x=element_blank())

如何删除 x 轴标签并将其另存为 ggplot 对象。此后,将它包裹在 ggplotly 周围,它应该可以解决问题。最小可重现示例如下;

library(plotly)
library(ggplot2)
# create a ggplot object and remove the x-axis label
bp <- ggplot(PlantGrowth, aes(x=group, y=weight)) + 
  geom_boxplot()+
  theme(axis.title.x=element_blank(), axis.text.x=element_blank(),
                      axis.ticks.x=element_blank())
# show the ggplot
bp
# create a ggplotly object from the ggplot object
p<- ggplotly(bp)
# show the ggplotly object
p

我认为这清楚地回答了你的问题。