0

Libraries being used

install.packages("rPref")
install.packages("dplyr")
install.packages("igraph")
install.packages("ggplot") 

Taking mtcars dataset from R as an example.

In order to find the Pareto frontier and level value one establish the preferences

p <- high(mpg) * high(hp) 

Then calculate the level-value w.r.t. p by using top-all

res <- psel(mtcars, p, top = nrow(mtcars))

When one creates the visualization as follows

gp <- ggplot(res, aes(x = mpg, y = hp, color = factor(.level))) + geom_point(size = 3)

It will show a plot with the mpg and hp values of mtcars with colors, and each of the color represents the level (proximity to optimum). As follows

enter image description here

If one wants to plot the Pareto front line for every area of all points of a lower level, one can run

gp + geom_step(direction = "vh") 

That results in

enter image description here

However, as for one's case only the 1st level is relevant, how does one display only the dots and the specific pareto front for level 1?

Changing the factor(.level) to factor(1) as

gp <- ggplot(res, aes(x = mpg, y = hp, color = factor(1))) + geom_point(size = 3)

Gives the following, which is ignoring the previous levels but some that would not belong to Level 1 seem to be featured in it

enter image description here

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83

1 Answers1

2

Is this what you're looking for?

data(mtcars)
p <- high(mtcars$mpg) * high(mtcars$hp) 

res <- psel(mtcars, p, top = nrow(mtcars))
res1 <- res %>% filter(.level == "1")
gp <- ggplot() + 
  geom_point(data = res, aes(x = mpg, y = hp, color = factor(.level)), size = 3) + 
  geom_step(data = res1 , aes(x=mpg, y=hp, color=factor(.level)))

enter image description here


Edit to resolve comments

Here's the same graph without the other points:

res %>% filter(.level == "1") %>% 
  ggplot() + 
    geom_point(aes(x = mpg, y = hp), size = 3) + 
    geom_step(aes(x=mpg, y=hp))

enter image description here

DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25
  • Yes, however without showing the points that belong to levels that are not the first one. And, ideally, auto-scaling it to fit the graph. – Gonçalo Peres Feb 01 '21 at 20:27
  • @GonçaloPeres龚燿禄 So you don't want to show the points for levels 2-5 at all, correct? Do you want to show the points belonging to group 1, or just the line? And what do you mean by auto-scaling? – DaveArmstrong Feb 01 '21 at 21:00
  • For the first question, yes (I don't want the points for levels 2-5 visible). For the second one, the points and line. The auto-scaling may by done automatically and it is optional, so nevermind with that part. – Gonçalo Peres Feb 01 '21 at 21:01