更改cplot中的X轴标签

huangapple go评论58阅读模式
英文:

Change X-axis Labels in cplot

问题

我有一个逻辑回归模型,想使用 cplot 函数绘制每个变量的平均边际效应。但我有一个分类变量,其标签很长,导致 cplot 产生重叠的 x 轴标签:

cplot(model,"Region", xlab = "Dwelling's Region")

如图所示,由于标签很长,它只显示了一半。我要如何创建一个没有 x 标签,只有数字(从1到12)的图表。我尝试了这个但没效果:

cplot(model,"Region", xlab = "Dwelling's Region")
axis(1, at = 1:12, labels = 1:12)
英文:

I have a logistic regression model and I want to plot the average marginal effects of each variable using the cplot function. But I have a categorical variable where the labels have long names, which causes the cplot to produce overlapping x-axis labels:

cplot(model,"Region", xlab = "Dwelling's Region")

更改cplot中的X轴标签

As you can see, because the names are long, it displays only half of them. How can I create a plot without x-labels, but only numbers, from 1 to 12. I tried this but it didn't work:

cplot(model,"Region", xlab = "Dwelling's Region")
axis(1, at = 1:12, labels = 1:12)

更改cplot中的X轴标签

答案1

得分: 1

似乎cplot()将额外的参数传递给默认的图形方法。关闭绘制x轴的标准方法是通过设置xaxt='n'。在help(par)中搜索xaxt

在您的情况下,应该这样做:

cplot(model, "区域", xlab = "住宅区域", xaxt='n')
axis(1, at = 1:12, labels = 1:12)
英文:

Seems like cplot() passes additional arguments to default graphics methods. The standard way to turn-off the drawing of x-axis is by setting xaxt='n'. Search for xaxt in help(par).

In your case this should work:

cplot(model,"Region", xlab = "Dwelling's Region", xaxt='n')
axis(1, at = 1:12, labels = 1:12)

huangapple
  • 本文由 发表于 2023年4月6日 23:38:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951334.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定