R 为什么xlim会切断连续比例的边界值?
给定数据帧:R 为什么xlim会切断连续比例的边界值?,r,plot,ggplot2,axis-labels,R,Plot,Ggplot2,Axis Labels,给定数据帧: d = structure(list(bin_start = 1:12, bin_count = c(12892838L, 1921261L, 438219L, 126650L, 41285L, 15948L, 6754L, 3274L, 1750L, 992L, 703L, 503L)), .Names = c("bin_start", "bi
d = structure(list(bin_start = 1:12,
bin_count = c(12892838L, 1921261L, 438219L, 126650L, 41285L,
15948L, 6754L, 3274L, 1750L, 992L, 703L, 503L)),
.Names = c("bin_start", "bin_count"),
class = "data.frame",
row.names = c(NA, 12L))
我可以用stat=“identity”
构建直方图:
看起来是这样的:
对长尾I极限x标度不满意(相当于xlim=c(1,6)
):
但是我得到了边界点x=1
和x=6
消失:
请注意,y轴仍像边界点一样缩放属于情节美学。这是功能还是bug?功能的副作用。由于您自己将数据装箱,因此您可能需要一个离散的比例,以及一个
x
的系数:
ggplot(d) +
geom_histogram(aes(x=factor(bin_start), y=bin_count), stat="identity", colour="black", fill="white") +
scale_x_discrete(limit=as.character(1:6))
尝试了缩放x\u离散(限制=3:6)
但我仍然得到x=1,2的条形图,但没有标签…尝试as.character(3:6)
。对于离散比例,限制
实际上应该是一个字符向量。我将修改我的答案。
ggplot(d) +
geom_histogram(aes(x=bin_start, y=bin_count), stat="identity", colour="black", fill="white") +
scale_x_continuous(breaks=1:12, limits=c(1,6))
ggplot(d) +
geom_histogram(aes(x=factor(bin_start), y=bin_count), stat="identity", colour="black", fill="white") +
scale_x_discrete(limit=as.character(1:6))