Visualization of coefficients in R (dot-chart)

RazorLazor

I want to plot my coefficients from three different models to show the shrinkage effect of the estimated coefficients with a dot-chart.

For more context: I am working with a hierarchical linear model and want to compare those estimates with the estimates of the complete pooling and the no pooling estimates.

Let's say we have a dataframe like this:

    a <- c(1,2,3,4)
    b <- c(2.5, 2.5, 2.5, 2.5)
    c <- c(1.2,2.3,2.8,3.7)
    city <- c("London", "Madrid", "Sidney", "Paris")
    df <- as.data.frame(cbind(city,a,b,c))
df <- df[order(df$a),]

I want to show them in a descending order kinda like in this picture but without the standard deviations, just the points. Is there a way to do that simply with ggplot?

dc37

Starting with your dataframe df, you can reshape your data using pivot_longer and conserve your data order by calling df$city in the scale_x_discrete:

library(tidyr)
df2 = df %>% pivot_longer(.,-city, names_to =  "Model", values_to = "value")

library(ggplot2)
ggplot(df2, aes(x = city, y = value, color = Model)) + geom_point() + coord_flip() + 
  scale_x_discrete(limits = df$city)

I re-arrange your dataframe df in order to get numerical values (using cbind in combination with dataframe tends to converts data into factor levels):

a <- c(1,2,3,4)
b <- c(2.5, 2.5, 2.5, 2.5)
c <- c(1.2,2.3,2.8,3.7)
city <- c("London", "Madrid", "Sidney", "Paris")
df <- data.frame(city,a,b,c)
df <- df[order(df$a),]

And you get the following graph enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related