在 ggplot2 中使用 scale_x_discrete() 自定义 x 轴时出错
Error in customizing the x axis with scale_x_discrete() in ggplot2
我有下图:
来自这段工作代码:
ggplot(plot, aes(x=variable, y=value, colour=Species, group=Species)) + geom_line() +
geom_point() + facet_grid(. ~ Treatment) + theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.title.y = element_blank(),
legend.text = element_text(face = "italic"), legend.key = element_blank(),legend.title=element_blank(),
legend.position="bottom", legend.background = element_rect(colour = 'black'))
不过我想删除 x 轴上的一些 YEARS。我试图将这段代码添加到主题(...)中,这应该可以解决问题,但没有成功:
scale_x_discrete(breaks = c("1993","1994","1995","1996","1998","2000","2003","2006","2014"))
R returns下面的错误我不明白:
Error in (function (el, elname) : "" is not a valid theme element name.
这是我数据的 str():
str(plot)
'data.frame': 616 obs. of 4 variables:
$ Species : Factor w/ 290 levels "Abarema jupunba",..: 21 24 32 48 54 60 62 81 117 139 ...
$ Treatment: chr "Conventional logging" "Conventional logging" "Conventional logging" "Conventional logging" ...
$ variable : Factor w/ 22 levels "1993","1994",..: 1 1 1 1 1 1 1 1 1 1 ...
$ value : num 1.34808 0.62532 0.20571 2.69961 0.00427 ...
不确定我提供的信息是否足够,但我想知道是否有人知道为什么这不起作用?
scale_x_discrete
应该出现在 theme(...)
.
之外
我有下图:
来自这段工作代码:
ggplot(plot, aes(x=variable, y=value, colour=Species, group=Species)) + geom_line() +
geom_point() + facet_grid(. ~ Treatment) + theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.title.y = element_blank(),
legend.text = element_text(face = "italic"), legend.key = element_blank(),legend.title=element_blank(),
legend.position="bottom", legend.background = element_rect(colour = 'black'))
不过我想删除 x 轴上的一些 YEARS。我试图将这段代码添加到主题(...)中,这应该可以解决问题,但没有成功:
scale_x_discrete(breaks = c("1993","1994","1995","1996","1998","2000","2003","2006","2014"))
R returns下面的错误我不明白:
Error in (function (el, elname) : "" is not a valid theme element name.
这是我数据的 str():
str(plot)
'data.frame': 616 obs. of 4 variables:
$ Species : Factor w/ 290 levels "Abarema jupunba",..: 21 24 32 48 54 60 62 81 117 139 ...
$ Treatment: chr "Conventional logging" "Conventional logging" "Conventional logging" "Conventional logging" ...
$ variable : Factor w/ 22 levels "1993","1994",..: 1 1 1 1 1 1 1 1 1 1 ...
$ value : num 1.34808 0.62532 0.20571 2.69961 0.00427 ...
不确定我提供的信息是否足够,但我想知道是否有人知道为什么这不起作用?
scale_x_discrete
应该出现在 theme(...)
.