df <- data.frame(product=c('prod A', 'prod B', 'prod C', 'prod D', 'prod E', 'prod F'),
count=c(40, 57, 50, 82, 17, 16))
df
##   product count
## 1  prod A    40
## 2  prod B    57
## 3  prod C    50
## 4  prod D    82
## 5  prod E    17
## 6  prod F    16
pareto.chart(df$count)

##    
## Pareto chart analysis for df$count
##     Frequency Cum.Freq. Percentage Cum.Percent.
##   D  82.00000  82.00000   31.29771     31.29771
##   B  57.00000 139.00000   21.75573     53.05344
##   C  50.00000 189.00000   19.08397     72.13740
##   A  40.00000 229.00000   15.26718     87.40458
##   E  17.00000 246.00000    6.48855     93.89313
##   F  16.00000 262.00000    6.10687    100.00000
mydf <- df[order(df$count,decreasing=TRUE),]
mydf
##   product count
## 4  prod D    82
## 2  prod B    57
## 3  prod C    50
## 1  prod A    40
## 5  prod E    17
## 6  prod F    16
mydf$product <- factor(mydf$product,levels = mydf$product)
mydf
##   product count
## 4  prod D    82
## 2  prod B    57
## 3  prod C    50
## 1  prod A    40
## 5  prod E    17
## 6  prod F    16
mydf$cumulative <- cumsum(mydf$count)
mydf 
##   product count cumulative
## 4  prod D    82         82
## 2  prod B    57        139
## 3  prod C    50        189
## 1  prod A    40        229
## 5  prod E    17        246
## 6  prod F    16        262
ggplot(mydf, aes(x=product))+
  geom_bar(aes(y=count),fill='blue',stat="identity") +
  geom_point(aes(y=cumulative),color='red',pch=16,size=2)+
  geom_path(aes(y=cumulative,group=1), color='red', lty=3,size=0.9)+
  theme(axis.text.x  = element_text(angle=45, vjust=0.6))+
  labs(title="Pareto Plot",x='Product',y='Aantal')
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.

totaal = max(mydf$cumulative)

mydf <- mydf %>% 
    select(product, count,cumulative) %>% 
    summarise(product ,count, cumulative, perc=round(100*count/totaal))

mydf$cumperc <- cumsum(mydf$perc)

ggplot(mydf, aes(x=product))+
  geom_bar(aes(y=count),fill='blue',stat="identity") +
  geom_point(aes(y=cumulative),color='red',pch=16,size=2)+
  geom_path(aes(y=cumulative,group=1), color='red', lty=3,size=0.9)+
  scale_y_continuous(sec.axis = sec_axis(~.*100/262, name = "Cumulatief [%]"))+
  labs(title="Pareto Plot",x='Product',y='Aantal [stuks]',colour="Parameter")+
  theme(axis.text.x  = element_text(angle=45, vjust=0.6), legend.position = c(0.7,0.9))

mydf
##   product count cumulative perc cumperc
## 1  prod D    82         82   31      31
## 2  prod B    57        139   22      53
## 3  prod C    50        189   19      72
## 4  prod A    40        229   15      87
## 5  prod E    17        246    6      93
## 6  prod F    16        262    6      99