R中的scale_x_discrete是一个用于离散变量的坐标轴缩放函数。它可以用来调整离散变量在x轴上的显示方式,使得数据更加清晰可读。 scale_x_discrete函数的参数包括: - br...
# 横坐标是离散变量,纵坐标是连续变量 p0 <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_point() # 其实scale_x_discrete函数主要参数也是上面颜色的离散变量函数的通用参数,在discrete_scale中查询 p0 + scale_x_discrete("cyl") # 更改坐标轴名称 p0 + scale_x_discrete(labels = c("4"="a",...
scale_x_discrete(labels = abbreviate)plot_grid(d, p2, p3, p4, labels = LETTERS[1:4], nrow = 2) 在D图中,我们使用abbreviate函数将X轴的标签设置为简写 9.3 日期和时间 虽然日期和时间也是连续型的,但是在标注坐标轴时还是有些不一样的。 共支持三种类型的时间日期,其中scale_*_date处理Date类型,sc...
如何在ggplot的scale_x_discrete中指定频率或断点?一种选择是使用lambda函数只为每个第四个类别添加一个...
在ggplot2中,可以使用scale_x_discrete()函数来更改分类变量的x轴大小。该函数可以接受多个参数来调整x轴的外观和行为。 首先,可以使用breaks参数来指定x轴上要显示的刻度值。例如,如果想要每隔一个刻度显示一个标签,可以使用breaks = seq(1, length(levels(data$variable)), 2)。 其次,可以使用labels参数来指定...
scale_x_discrete(labels = str_wrap(my_labels, 10)) ## based on: https://stackoverflow.com/a/21894897/6105259 可以看出,仅仅添加stringr::str_wrap()就打乱了标签的顺序。这个问题在其他包装技术中重复出现(例如,这一种)。 知道我如何为x轴标签指定外部命名向量,并在保留正确顺序的同时在RTL语言(e.g...
p2 <- ggplot(mtcars, aes(wt, mpg))+geom_point()+scale_x_continuous(name="log2",trans="log2")grid.arrange(p1,p2,ncol=2) position 设定坐标轴的位置,x轴 “top”、“bottom” ,y轴 "left"、"right" 对于离散型数据 scale_x_discrete()、scale_y_discrete() 函数的用法和连续型变量的用法...
如何在ggplot的scale_x_discrete中指定频率或断点?一种选择是使用lambda函数只为每个第四个类别添加一个...
ggplot(data=Salaries,aes(x=rank, y=salary, fill=sex)) + geom_boxplot() + scale_x_discrete(breaks=c("AsstProf","AssocProf","Prof"), labels=c("Assistant\nProfessor", "Associate\nProfessor", "Full\nProfessor")) + scale_y_continuous(breaks=c(50000, 100000, 150000, 200000), ...
> scalexx <- scalex[grepl("scale_shape.+", scalex)] > unique(gsub("(([^_]+_){2})(.+)","\\3",scalexx)) [1] "binned" "continuous" "discrete" "identity" "manual" "ordinal" # x轴 > scalexx <- scalex[grepl("scale_x.+", scale...