R:删除 X 轴上未绘制的名称的方法(保留已绘制的名称)? [英] R: Way to Remove Names on X Axis That Were Not Plotted (Leaving Names That Were)?

查看:31
本文介绍了R:删除 X 轴上未绘制的名称的方法(保留已绘制的名称)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码可以获取前 10 个频率并绘制一个图:

I have this code that gets the top 10 frequencies and makes a plot:

top_n(data.3, n=10, (Frequency)) %>% barplot(Frequency~ICD10Code, data = .,cex.name=.5)

出现的问题是我当时没有想到的问题,它确实绘制了 10 个最多的频率,但它还包括所有未绘制的 ICD10Code 名称.

The issue that arises, that didn't occur to me at the time, is that it does plot the 10 most frequencies but it also includes all the ICD10Code names that were not plotted.

有没有一种方法可以在不使用xaxt='n' 和/或axis() 的情况下利用现有代码,其中只有 10 个最频繁的 ICD10Codes 和相应的频率显示在图中?

Is there a way to utilize the existing code perhaps without usingxaxt='n' and/or axis() to where only the 10 most frequent ICD10Codes and respective frequencies are shown on plot?

推荐答案

可能这些名称仍然存在,因为它们是您因子中的级别,因此它仍然可以识别它们.如果您将其设为字符变量,则级别应该会消失.

Probably the names are still there because they are levels in your factor, so it still recognizes them. If you make it a character variable the levels should dissappear.

top_n(data.3, n=10, (Frequency)) %>% 
     mutate(ICD10Code = as.character(ICD10Code)) %>%
     barplot(Frequency~ICD10Code, data = .,cex.name=.5)

如果由于某种原因仍然显示为因子,则将 mutate 更改为 mutate(ICD10Code = as.character(droplevels(ICD10Code)))

If it for some reason still displays as factor, than change the mutate to mutate(ICD10Code = as.character(droplevels(ICD10Code)))

这篇关于R:删除 X 轴上未绘制的名称的方法(保留已绘制的名称)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆