ggplot2删除轴标签

Pro*_*eus 4 r ggplot2 plotly ggplotly

我有以下数据集:

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"))
Run Code Online (Sandbox Code Playgroud)

我正在使用ggplot2绘制以下线/点图.

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)
Run Code Online (Sandbox Code Playgroud)

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

我也尝试过添加:

theme(legend.title = element_blank(), axis.text = element_blank())
Run Code Online (Sandbox Code Playgroud)

不知道我做错了什么.

任何提示?

更新

这是我得到的情节:

在此输入图像描述

Prr*_*dep 7

要删除x轴标签,你应该尝试使用axis.text.x=element_blank()theme()

删除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())
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


mnm*_*mnm 7

如何删除 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
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

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