Skip to content

Commit

Permalink
fixed plotting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
osorensen committed Nov 23, 2023
1 parent 453d26e commit f59132f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
5 changes: 0 additions & 5 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ validate_permutation <- function(vec) {
}
}

# Function for getting an x axis without decimals.
# Modified from https://stackoverflow.com/questions/21061653/creating-a-density-histogram-in-ggplot2
scalefun <- function(x) sprintf("%d", as.integer(x))


# function taken from PLMIX package:
# Copyright Cristina Mollica and Luca Tardella
unit_to_freq <- function(data) {
Expand Down
14 changes: 3 additions & 11 deletions R/plot.BayesMallows.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,12 @@ plot_rho <- function(x, items, burnin = 0) {
}

df <- x$rho[x$rho$iteration > burnin & x$rho$item %in% items, , drop = FALSE]

# Compute the density, rather than the count, since the latter
# depends on the number of Monte Carlo samples
df <- aggregate(
list(n = df$iteration),
list(cluster = df$cluster, item = df$item, value = df$value),
FUN = length
)
df$pct <- df$n / sum(df$n)
df1 <- aggregate(iteration ~ item + cluster + value, data = df, FUN = length)
df1$pct <- df1$iteration / length(unique(df$iteration))

# Finally create the plot
p <- ggplot2::ggplot(df, ggplot2::aes(x = .data$value, y = .data$pct)) +
p <- ggplot2::ggplot(df1, ggplot2::aes(x = factor(.data$value), y = .data$pct)) +
ggplot2::geom_col() +
ggplot2::scale_x_continuous(labels = scalefun) +
ggplot2::xlab("rank") +
ggplot2::ylab("Posterior probability")

Expand Down

0 comments on commit f59132f

Please sign in to comment.