[英]How can I get rid of the blank space being left on the plot panel in R?
This is the desired output: similar to output by subsetting这是所需的输出:类似于通过子集输出
I am using scale_x_discrete to set the limits of the x axis.我正在使用 scale_x_discrete 来设置 x 轴的限制。 I would like to know how to get rid of the blank space left on the panel and have the defined limits fill the entire axis.
我想知道如何摆脱面板上留下的空白空间并使定义的限制填充整个轴。
myplot <- ggplot(diamonds, aes(x = clarity, fill = cut)) + #data
geom_bar() + #geom
scale_x_discrete(limits = c("I1", "SI2", "VS2"),
name = "Clarity of Stones") #setting limits #limits
myplot
If your goal is to subset your data for particular measures (clarity in this case), you should do this within the data object provided.如果您的目标是针对特定度量(在本例中为清晰)对数据进行子集化,则应在提供的数据对象中执行此操作。 As in:
如:
ggplot(diamonds[diamonds$clarity %in% c("I1", "SI2", "VS2"),], aes(x = clarity, fill = cut)) +
geom_bar()
Its probably just a syntax problem since you missed a parenthesis at the end of your limits
argument, and the name of the scale is wrongly passed as a fourth column of your X-axis.它可能只是一个语法问题,因为您在
limits
参数的末尾错过了一个括号,并且比例的名称被错误地作为 X 轴的第四列传递。 You shoud run:你应该运行:
ggplot(diamonds, aes(x = clarity, fill = cut)) + geom_bar() +
scale_x_discrete(limits = c("I1", "SI2", "VS2"), name = "Clarity of Stones")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.