Learn R Programming

rPref (version 0.1)

get_btg: Better-Than-Graph

Description

Returns a Hasse-Diagramm of a preference order (also called the Better-Than-Graph) on a given dataset to be plotted with the igraph package.

Usage

get_btg(df, pref)

Arguments

df
A dataframe.
pref
A preference on the columns of df, see psel for details.

Details

This function returns a list l with the following list entries: [object Object],[object Object] To plot the resulting graph, use the plot function as follows: plot(l$graph, layout = l$layout). For more details, see igraph.plotting and the examples below. The Hasse diagram of a preference visualizes all the better-than-relationsships on a given dataset. All the edges which can be retrieved by transitivity of the the order are omitted. The names of the vertices are characters ranging from "1" to as.character(nrow(df)) and they correspond to the row numbers of df.

See Also

igraph.plotting

Examples

Run this code
# Pick a small data set and create preference / BTG
df <- mtcars[1:10,]
pref <- high(mpg) * high(hp)
btg <- get_btg(df, pref)

# Create labels for the nodes with relevant values
labels <- paste0(df$mpg, "\n", df$hp)

# Plot the graph using igraph
library(igraph)
plot(btg$graph, layout = btg$layout, vertex.label = labels,
     vertex.size = 25)

# Add colors for the maxima nodes and plot again
colors <- rep(rgb(1,1,1), nrow(df))
colors[psel.indices(df, pref)] <- rgb(0,1,0)
plot(btg$graph, layout = btg$layout, vertex.label = labels,
     vertex.size = 25, vertex.color = colors)

# Show lattice structure of 3-dimensional Pareto preference
df <- merge(merge(list(x = 1:3), list(y = 1:3)), list(z = 1:2))
labels <- paste0(df$x, ",", df$y, ",", df$z)
btg <- get_btg(df, low(x) * low(y) * low(z))
plot(btg$graph, layout = btg$layout, vertex.label = labels,
     vertex.size = 20)

Run the code above in your browser using DataLab