我正在使用plot_missing函数显示数据集中的NA数量。由于我的数据集有50个变量,因此我需要调整文本大小。我设法更改了轴的文本大小,但没有更改数据标签的文本大小。有什么建议吗?
使用示例数据集:
var gulp = require("gulp"),
browser = require("browser-sync").create(),
less = require("gulp-less"),
autoprefixer = require('gulp-autoprefixer'),
sourcemaps = require("gulp-sourcemaps"),
concat = require('gulp-concat'),
clean = require('gulp-rimraf'),
gulpCopy = require('gulp-copy');
//Sincronización de pantallas
gulp.task('browser-sync', () => {
browser.init({
server: {
baseDir: './public'
},
notify: {
styles: {
top: 'auto',
bottom: '0'
}
},
injectChanges: true
});
});
//Refrescar pantalla
gulp.task('re-loaded', function() {
console.log("a")
browser.reload()
});
gulp.task('watch', () => {
gulp.watch('src/js/*.js', gulp.series('cleanJs', 'generateJs', 're-loaded'));
gulp.watch('src/css/*.less', gulp.series('cleanCss', 'less', 're-loaded'));
gulp.watch('src/**/*.html', gulp.series('cleanHtml', gulp.parallel('generateHtml', 're-loaded')));
gulp.watch('src/img/**/**.*', gulp.series('cleanImg', 'copy', 're-loaded'));
gulp.watch('src/libs/**/**.*', gulp.series('cleanLibs', 'copy', 're-loaded'));
gulp.watch('src/fonts/**.*', gulp.series('cleanFonts', 'copy', 're-loaded'));
});
//Generar nuevo HTML en public
gulp.task('generateHtml', () => {
gulp.src('src/*.html')
.pipe(gulp.dest('./public/'))
});
//Actualización de las funciones JS cuando guardemos
gulp.task('generateJs', () => {
gulp.src('src/js/*.js')
.pipe(concat("script.js"))
.pipe(gulp.dest('./public/js'))
});
//Actualización de los estilos CSS cuando guardemos
gulp.task('less', () => {
gulp.src(['src/*.less'])
.pipe(less({
// pretty: true
}))
.pipe(autoprefixer('last 2 versions'))
.pipe(concat("style.css"))
.pipe(gulp.dest('./public/css'))
});
//Copiar a public
gulp.task('copy', () => {
return gulp
.src(['src/fonts/**/**.*', 'src/img/**/**.*', 'src/libs/**/**.*'])
.pipe(gulpCopy('./public/', {prefix: 1} ));
});
//Borrar imágenes de public
gulp.task('cleanImg', () => {
return gulp.src("./public/img/**/**.*", { read: false }).pipe(clean());
});
//Borrar librerías de public
gulp.task('cleanLibs', () => {
return gulp.src("./public/libs/**/**.*", { read: false }).pipe(clean());
});
//Borrar fuentes de public
gulp.task('cleanFonts', () => {
return gulp.src("./public/fonts/**/**.*", { read: false }).pipe(clean());
});
//Borrar JS de public
gulp.task('cleanJs', () => {
return gulp.src("./public/js/*", { read: false }).pipe(clean());
});
//Borrar CSS de public
gulp.task('cleanCss', () => {
return gulp.src("./public/css/*.css", { read: false }).pipe(clean());
});
//Borar HTML de public
gulp.task('cleanHtml', () => {
return gulp
.src("./public/*.html", { read: false })
.pipe(clean());
});
gulp.task('default', gulp.parallel('generateHtml', 'generateJs', 'less', 'browser-sync', 'watch', 'copy'));
答案 0 :(得分:1)
可能有更优雅的方法来执行此操作,但是在这里我修改了plot_missing
函数:
plot_missing_smaller_labels <-
function (data, title = NULL, ggtheme = theme_gray(),
theme_config = list(legend.position = c("bottom")))
{
pct_missing <- NULL
missing_value <- profile_missing(data)
output <- ggplot(missing_value, aes_string(x = "feature",
y = "num_missing", fill = "group")) +
geom_bar(stat = "identity") +
geom_text(aes(label = paste0(round(100 * pct_missing, 2), "%")), size = 2) +
scale_fill_manual("Group", values = c(Good = "#1a9641",
OK = "#a6d96a", Bad = "#fdae61", Remove = "#d7191c"),
breaks = c("Good", "OK", "Bad", "Remove")) +
coord_flip() +
xlab("Features") +
ylab("Missing Rows")
class(output) <- c("single", class(output))
plotDataExplorer(plot_obj = output, title = title, ggtheme = ggtheme,
theme_config = theme_config)
}
我在size = 2
函数中添加了geom_text()
。
新的plot_missing_smaller_labels
函数的调用方式如下:
plot_missing_smaller_labels(df, theme_config=list(axis.text=element_text(size = 6)))
哪个标签的文本较小。