Reputation: 187
I want to use scale_x_continuous and round my labels to nearest thousand. For example if my X axis are 1234567,2345566.... I want it to be 1235,2346.I have used sequencing to split my x-axis in deciles. When I am rounding it to thousands and then dividing by 1000 I will show it by example. Its making 1235000 and after dividing its becoming 1235 which I want but since sclae_x_continuous observes that all the numbers till 3million(which is now 3k) comes in the first decile its printing all the labels at the same place. The code I am using is:
ggplot(
data = cummulative,
aes(
x = seq(1,length(cummulative$Frequency)),
y = Cum.Percent.,
group = 1
)
) +
geom_line(colour="red", size=1) +
theme_classic() +
theme(axis.text.x = element_text(angle = 75, hjust = 1, size=8)) +
labs(x="Number of Customer (in thousands)",y="Product Share (%)") +
ggtitle("Pareto Chart") +ylim(0,100.1) +
(scale_x_continuous(
breaks = seq(
0,
length(cummulative$Frequency),
length(cummulative$Frequency)/10
)
))
Please also find the image here:
Thanks a lot guys :)
Upvotes: 1
Views: 1440
Reputation: 18487
Let ggplot
handle the breaks instead of specifying them manually. You'll get a nice interval. Dividing X a priori by 1000 will get you very close to the solution.
Provide a reproducible example if you want a better solution.
ggplot(
data = cummulative,
aes(
x = seq_along(Frequency) / 1000,
y = Cum.Percent.
)
) +
geom_line(colour="red", size=1) +
theme_classic() +
theme(axis.text.x = element_text(angle = 75, hjust = 1, size=8)) +
labs(
x = "Number of Customer (in thousands)",
y = "Product Share (%)"
) +
ggtitle("Pareto Chart") +
ylim(0, 100.1) +
scale_x_continuous()
Upvotes: 2