R ggplot2显示不在数据中的列
我认为ggplot有问题,非常严格,但不知怎么的,它显示的数据不在那里,我如何才能摆脱它似乎显示x=2和5列的空白空间R ggplot2显示不在数据中的列,r,ggplot2,R,Ggplot2,我认为ggplot有问题,非常严格,但不知怎么的,它显示的数据不在那里,我如何才能摆脱它似乎显示x=2和5列的空白空间 Data <- structure(list(DQRNiveau = c(0, 1, 3, 4, 6, 7, 8, 0, 1, 3, 4, 6, 7, 8), Group = c("Alpha", "Alpha", "Alpha", "Alpha", "Alpha", "Alpha", "Alpha", "Beta", "Beta", "Bet
Data <- structure(list(DQRNiveau = c(0, 1, 3, 4, 6, 7, 8, 0, 1, 3, 4, 6, 7, 8),
Group = c("Alpha", "Alpha", "Alpha", "Alpha", "Alpha", "Alpha", "Alpha", "Beta", "Beta", "Beta", "Beta", "Beta", "Beta", "Beta"),
n_Count = c(2L, 4L, 11L, 77L, 45L, 102L, 13L, 2L, 4L, 16L, 103L, 58L, 109L, 13L)),
.Names = c("DQRNiveau", "Group", "n_Count"), row.names = c(NA, -14L),
class = c("tbl_df", "tbl", "data.frame"))
ggplot(data = Data, aes(DQRNiveau, y = n_Count, fill = Group)) +
geom_bar(stat = "identity", position = position_dodge(1)) +
scale_x_continuous(breaks = c(Data$DQRNiveau))
Data因为DQRNiveau
是数字,所以它会创建空格。如果您将其转换为字符,它应该可以正常工作,因为它将其视为一个分类变量
ggplot(data = Data, aes(as.character(DQRNiveau), y = n_Count, fill = Group)) +
geom_bar(stat = "identity", position = position_dodge(1)) +
xlab('DQRNiveau')
您要求的是连续刻度,但在2和5处不连续