I am using this code to create a Pareto chart, but it does not work well on this dataset, the x-axis becomes unsorted in the graph
cds <- catsvdogs
newdata <- cds[order(-cds$`Number of Households (in 1000)`),]
newdata <- data.frame(newdata$Location,newdata$`Number of Households (in 1000)`)
newdata <- newdata[c(1:10),c(1:2)]
newdata$cumulative <- cumsum(newdata$newdata..Number.of.Households..in.1000..)
ggplot(newdata, aes(x=newdata[,1])) +
geom_bar(aes(y=newdata[,2]), fill='blue', stat="identity") +
geom_point(aes(y=cumulative), color = rgb(0, 1, 0), pch=16, size=1) +
geom_path(aes(y=cumulative, group=1), colour="slateblue1", lty=3, size=0.9) +
theme(axis.text.x = element_text(angle=90, vjust=0.6)) +
labs(title = "Pareto Plot", x = 'Cities', y =
'Count')