R ggplot2条形图不显示scale_x_离散()中定义的标签

R ggplot2条形图不显示scale_x_离散()中定义的标签,r,ggplot2,labels,R,Ggplot2,Labels,我的数据集如下所示: Index Feature scaled_Gain sign_Correlation 1 a 1.00000000 1 2 b 0.60999674 1 3 c 0.54824913 1 4 d 0.11134079 1 5 e 0.06530486 1 6 f 0.06470836 1 7 g 0.06263247 1 8 h

我的数据集如下所示:

 Index  Feature scaled_Gain sign_Correlation
    1   a   1.00000000  1
    2   b   0.60999674  1
    3   c   0.54824913  1
    4   d   0.11134079  1
    5   e   0.06530486  1
    6   f   0.06470836  1
    7   g   0.06263247  1
    8   h   0.04166633  1
    9   i   0.03242897  -1
    10  j   0.02913138  1
ggplot(data = plot_data) +
geom_bar(aes(x = Index, y = scaled_Gain, fill = sign_Correlation), stat = "identity", alpha = 0.5) + 
theme_economist() + ggtitle("Scaled Gain")  + scale_x_discrete(labels = plot_data$Feature)
library(ggplot2)

ggplot(df, aes(Feature, scaled_Gain, fill = factor(sign_Correlation))) +
  geom_bar(stat = "identity", alpha = 0.5) + 
  ggtitle("Scaled Gain") + 
  labs(fill = "Sign Correlation") +
  ggthemes::theme_economist()
我的代码如下:

 Index  Feature scaled_Gain sign_Correlation
    1   a   1.00000000  1
    2   b   0.60999674  1
    3   c   0.54824913  1
    4   d   0.11134079  1
    5   e   0.06530486  1
    6   f   0.06470836  1
    7   g   0.06263247  1
    8   h   0.04166633  1
    9   i   0.03242897  -1
    10  j   0.02913138  1
ggplot(data = plot_data) +
geom_bar(aes(x = Index, y = scaled_Gain, fill = sign_Correlation), stat = "identity", alpha = 0.5) + 
theme_economist() + ggtitle("Scaled Gain")  + scale_x_discrete(labels = plot_data$Feature)
library(ggplot2)

ggplot(df, aes(Feature, scaled_Gain, fill = factor(sign_Correlation))) +
  geom_bar(stat = "identity", alpha = 0.5) + 
  ggtitle("Scaled Gain") + 
  labs(fill = "Sign Correlation") +
  ggthemes::theme_economist()
该图如下所示:

 Index  Feature scaled_Gain sign_Correlation
    1   a   1.00000000  1
    2   b   0.60999674  1
    3   c   0.54824913  1
    4   d   0.11134079  1
    5   e   0.06530486  1
    6   f   0.06470836  1
    7   g   0.06263247  1
    8   h   0.04166633  1
    9   i   0.03242897  -1
    10  j   0.02913138  1
ggplot(data = plot_data) +
geom_bar(aes(x = Index, y = scaled_Gain, fill = sign_Correlation), stat = "identity", alpha = 0.5) + 
theme_economist() + ggtitle("Scaled Gain")  + scale_x_discrete(labels = plot_data$Feature)
library(ggplot2)

ggplot(df, aes(Feature, scaled_Gain, fill = factor(sign_Correlation))) +
  geom_bar(stat = "identity", alpha = 0.5) + 
  ggtitle("Scaled Gain") + 
  labs(fill = "Sign Correlation") +
  ggthemes::theme_economist()

我的问题是:为什么标签不显示在x轴上?

请尝试以下操作:

 Index  Feature scaled_Gain sign_Correlation
    1   a   1.00000000  1
    2   b   0.60999674  1
    3   c   0.54824913  1
    4   d   0.11134079  1
    5   e   0.06530486  1
    6   f   0.06470836  1
    7   g   0.06263247  1
    8   h   0.04166633  1
    9   i   0.03242897  -1
    10  j   0.02913138  1
ggplot(data = plot_data) +
geom_bar(aes(x = Index, y = scaled_Gain, fill = sign_Correlation), stat = "identity", alpha = 0.5) + 
theme_economist() + ggtitle("Scaled Gain")  + scale_x_discrete(labels = plot_data$Feature)
library(ggplot2)

ggplot(df, aes(Feature, scaled_Gain, fill = factor(sign_Correlation))) +
  geom_bar(stat = "identity", alpha = 0.5) + 
  ggtitle("Scaled Gain") + 
  labs(fill = "Sign Correlation") +
  ggthemes::theme_economist()

我认为这里唯一的问题是,您使用的是
aes(索引,缩放增益)
而不是
aes(功能,缩放增益)

可能重复的