英文:
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")
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)
答案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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论