Too many factors on x axis
You can flip the values.
ggplot(data.frame(x=factor(trunc(runif(10000, 0, 100)), ordered=T)), aes(x=x)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
geom_histogram()
flip <- ggplot(data.frame(x=factor(trunc(runif(10000, 0, 100)), ordered=T)), aes(x=x)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
geom_histogram()
If it's still too dense for your taste, you can set manual breaks. In this case, I use five.
prune <- ggplot(data.frame(x=factor(trunc(runif(10000, 0, 100)), ordered=T)), aes(x=x)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
scale_x_discrete(breaks = seq(0, 100, by = 5)) +
geom_histogram()
library(gridExtra)
grid.arrange(flip, prune)
Too many labels on axis
Your column value
is likely a factor, when it should be a numeric. This causes each categorical value of value
to be given its own entry on the y-axis, thus producing the effect you've noticed.
You should coerce it to be a numeric
data$value <- as.numeric(as.character(data$value))
Note that there is probably a good reason it has been interpreted as a factor and not a numeric, possibly because it has some entries that are not pure numeric values (maybe 1,000
or 1000 m
or some other character entry among the numbers). The consequence of the coercion may be a loss of information, so be warned or cleanse the data thoroughly.
Also, you appear to have the same problem on the x-axis.
X-axis tick labels are too dense when drawing plots with matplotlib
A quick dirty solution would be the following:
ax.set_xticks(ax.get_xticks()[::2])
This would only display every second xtick. If you wanted to only display every n-th tick you would use
ax.set_xticks(ax.get_xticks()[::n])
If you don't have a handle on ax
you can get one as ax = plt.gca()
.
Alternatively, you could specify the number of xticks to use with:
plt.locator_params(axis='x', nbins=10)
Choosing how many x axis labels display on an altair chart in python
You have declared that your x data is type O
, meaning ordinal, i.e. ordered categories. This says that you want one distinct x bin for each unique value in your dataset. If you want fewer ordinal x bins, you should use a dataset with fewer unique values.
Alternatively, if you don't want each unique x value to have its own label, you can use the quantitative data type (i.e. x=alt.X('norm:Q')
), or perhaps bin your data x=alt.X('norm:O', bin=True)
. Be sure to bin your color encoding as well if you use the latter.
Garbled x-axis labels in matplotlib subplots
Suggestions:
- Increase the height of the figure.
fig, axes = plt.subplots(14, 4, figsize = (12,20), sharex = True)
- Rotate all the labels:
fig.autofmt_xdate(rotation=90)
- Use
tight_layout
at the end instead ofsubplots_adjust
:fig.tight_layout()
Related Topics
Configuration Failed Because Libcurl Was Not Found
How to Access Global/Outer Scope Variable from R Apply Function
Display HTML File in Shiny App
Lapply to Add Columns to Each Dataframe in a List
Reading Big Data with Fixed Width
Deleting Every N-Th Row in a Dataframe
How to Find Difference Between Values in Two Rows in an R Dataframe Using Dplyr
Output a Good-Looking Matrix Using Rendertable()
Align Two Data.Frames Next to Each Other with Knitr
Find All Combinations of Numbers That Sum to a Target
Use Rollapply and Zoo to Calculate Rolling Average of a Column of Variables
Using Dplyr Within a Function, Non-Standard Evaluation
Count Every Possible Pair of Values in a Column Grouped by Multiple Columns
Add Column Containing Data Frame Name to a List of Data Frames