I have a dataset in which I have two groups that underwent test and retest measurements. I created a figure displaying four boxplots (groups x tests) with points for each measurement. Test and retest scores are connected by a line for each subject and the boxplots are colored according to the test or retest session.
Now I would like to fill or un-fill the boxplots according to the group. I have create the figure below by creating two figures (filled and unfilled) by switching the geom_boxplot options in the code below and then merging them in photoshop. However, I was wondering if there is a way to create this figure completely with ggplot?
library(ggplot2)
group <- c("HC","HC","HC","HC","HC","HC","HC","HC","HC","HC","HC","HC","HC","HC","PAT","PAT","PAT","PAT","PAT","PAT","PAT","PAT","PAT","PAT")
session <- c("test","retest","test","retest","test","retest","test","retest","test","retest","test","retest","test","retest","test","retest","test","retest","test","retest","test","retest","test","retest")
value <- c(2,1.998521753,1.874733659,1.718486493,1.623289857,1.546827187,1.423472302,1.391178972,1.706069109,1.633178623,1.55107172,1.529644866,1.85152853,1.955804538,1.642797713,1.618263891,1.332975483,1.191228234,1.314644375,1.18511437,1.881207152,1.764699552,1,1.001585308)
index <- c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12)
df <- data.frame(group, session, value, index, U = interaction(session,group))
p <- ggplot(df, aes(x=U, y=value))
p <- p + geom_boxplot(aes(fill=session), data=df, colour="black", outlier.alpha=0.0, lwd=0.8, alpha=0.94)
# p <- p + geom_boxplot(aes(colour=session), data=df, outlier.alpha=0.0, lwd=0.8)
dat <- ggplot_build(p)$data[[1]]
p <- p + geom_segment(data=dat, aes(x=xmin, xend=xmax, y=middle, yend=middle), colour="grey70", size=1.6)
p <- p + stat_summary(fun.y=mean,geom="point",pch="-",colour="grey30",size=8, position = position_dodge(width=0.75))
p <- p + geom_line(aes(group = index), alpha = 0.7, colour ="grey50", data=df)
p <- p + geom_point(size=2, aes(group=session), colour="black", data=df, position = position_dodge(width=0.75))
p <- p + scale_x_discrete(labels=c("HC-test","HC-retest","PAT-test","PAT-retest"))
p <- p + scale_y_continuous(limits=c(0.9,2.1), breaks=c(1,1.5,2))
p <- p + scale_colour_manual(values=c("#bf812d","#35978f"))
p <- p + scale_fill_manual(values=c("#bf812d","#35978f"))
p <- p + theme_bw()
p <- p + theme(
axis.text.x = element_text(colour = "black"),
axis.text.y = element_text(colour = "black"),
axis.title.x = element_blank(),
axis.title.y = element_text(colour = "black"),
legend.position = "none",
panel.border = element_rect(colour = "black", fill=NA, size=1)
)
p <- p + labs(y=expression("Normalized Volume(mm)"^3))
ggsave("~/Desktop/test.pdf", width=5, height=4, units=c("in"), plot=p)
You could try to set the factor order differently. You also need to specify sufficient number of values in scale_xxx_manual. I have stripped down the example to include the boxes only, because this was your focal issue.
df$session <- factor(df$session, levels = c("test", "retest"))
df$U = interaction(df$group, df$session, lex.order = TRUE)
ggplot(df, aes(x = U, y = value, fill = U, color = U)) +
geom_boxplot() +
scale_fill_manual(values = c("white", "white", "#bf812d", "#35978f"), guide = "none") +
scale_color_manual(values = c("#bf812d", "#35978f", "black", "black"), guide = "none")
Related
I am making a 2 group dot plot comparing each group for their ability to achieve a certain percentage of 4 different outcomes. Right now I have my graph exactly how I want it showing 2 colors (one for each group) and the mean plus standard deviation in black. My problem is my legend is showing the mean dots as the 2 different groups and I want it to show the group color dots. Any idea how I can fix it without having to change the mean to the color of the groups? The graph and code are attached. Thanks!
####GG Plot Package
library(ggplot2)
####Using tapply function
perc = read.csv("sealedvsunsealed.csv", header=TRUE)
perc
percmean <- tapply(perc$Percentage, list(perc$Group, perc$Hydrogels), mean)
percsd <- tapply(perc$Percentage, list(perc$Group, perc$Hydrogels), sd)
percmean
percsd
####Subseting the data (which function)
GI <- perc[which(perc$Hydrogels == 'Successful \nInjection'),]
A <- perc[which(perc$Hydrogels == 'Aggregation\nObserved'),]
CA <- perc[which(perc$Hydrogels == 'Cylindrical \nAggregates'),]
CLA <- perc[which(perc$Hydrogels == 'Fully Fills\nChannel'),]
GI
A
CA
CLA
####Create an ANOVA table
GI.aov <- aov(Percentage ~ Group, data = GI)
A.aov <- aov(Percentage ~ Group, data = A)
CA.aov <- aov(Percentage ~ Group, data = CA)
CLA.aov <- aov(Percentage ~ Group, data = CLA)
####Conduct a Tukey's multiple comparision procedure
TukeyHSD(GI.aov)
TukeyHSD(A.aov)
TukeyHSD(CA.aov)
TukeyHSD(CLA.aov)
####Grouped Dot Plot with stats added
vF = ggplot(perc, aes(x=factor(perc$Hydrogels, level = level_order), y=Percentage, fill=perc$Group)) +
geom_dotplot(binaxis='y', stackdir='center', position = position_dodge(0.7))+
theme(legend.position = "right", legend.title = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"),
axis.text = element_text(size = rel(1.5)),
axis.title.y = element_text(size = rel(1.5)))
vF
vF + stat_summary(fun.y=mean, geom ="point", shape=18, size=4, position = position_dodge(0.7)) +
stat_summary(fun.ymin=function(x)(mean(x)-sd(x)),
fun.ymax=function(x)(mean(x)+sd(x)),
position = position_dodge(0.7),
colour = "black",
geom="errorbar", width=0.3, size=1)+
labs(x = NULL)
Data
Graph showing correct layout but incorrect legend
Note you are missing level_order from your code, i guessed it from your plot
level_order = levels(perc$Hydrogels)[c(4,1,2,3)]
If you can do without the legend for the mean (i.e the diamond), you can just do:
vF + stat_summary(fun.y=mean, geom ="point", shape=18, size=4,
position = position_dodge(0.7),show.legend=FALSE) +
new_scale_color()+
stat_summary(fun.ymin=function(x)(mean(x)-sd(x)),
fun.ymax=function(x)(mean(x)+sd(x)),
position = position_dodge(0.7),
colour = "black",
geom="errorbar", width=0.3, size=1)
I have a Shiny app that basically produces a graph based on the lines that the user selects in the tables. There are two tables : the first one produces the first 3 bars on the left (benchmark), the other ones come from the second table.
My question to you is : in your opinion, is it possible to leave the first 3 bars on the left in blue, and use other colors for all the others?
Here is the code I used in the App to produce the graphs :
output$graphPost <- renderPlot({
s <- input$posttestsdata_rows_selected
y <- input$benchmarkdata_rows_selected
tempBench <- benchmarkData[y]
meltedBench <- melt(tempBench)
tempPost <- postTestsData[s]
colnames(tempBench)[1] <- "x"
colnames(tempPost)[1] <- "x"
postTestsDataForGraph <- rbind(tempBench, tempPost)
meltPostTests <- melt(postTestsDataForGraph)
meltPostTests$x <- factor(meltPostTests$x, levels=unique(meltPostTests$x))
postTestsPlot <<- ggplot() +
geom_bar(data = meltPostTests, aes(x = as.factor(x), y = value, fill = variable), stat='identity', position = "dodge") +
theme(axis.line=element_blank(),
axis.text.y=element_blank(),
axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
panel.background=element_blank(),
panel.border=element_blank(),
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
plot.background=element_blank()) +
geom_hline(yintercept = meltedBench$value, color = c("#1F497D", "#4F81BD", "#8DB4E3")) +
geom_text(aes(x = as.factor(meltPostTests$x), y = meltPostTests$value, fill=meltPostTests$variable, label = paste(meltPostTests$value,"%", sep = "")), position=position_dodge(width=0.9), vjust=-0.25) +
scale_fill_manual(values = c("#1F497D", "#4F81BD", "#8DB4E3"))
return(postTestsPlot)
})
Thanks,
RĂ©mi
To influence the colors of the first 3 bars, you need to use another value for aesthetic fill than variable
For example:
require(ggplot2)
set.seed(314)
dat <- data.frame(x = rep(1:3,10),
variable = sample(1:3, 30, replace = T))
dat$c <- as.factor(ifelse(dat$x == 1,1,dat$variable+1))
ggplot(dat, aes(x = interaction(variable,x), fill = c)) +
geom_bar(data = dat, aes(fill = c), position = position_dodge()) +
scale_x_discrete(breaks = c('2.1','2.2','2.3'),
labels = unique(dat$variable))
gives:
I have the following code. How can I make the grid much finer scale? Also not sure why the legend is not showing? Like I want to have 4 o 8 squares between 75 and 100.
#Select the colors from http://colorbrewer2.org/#type=sequential&scheme=RdPu&n=9
if( !is.element("ggplot2", installed.packages()[,1]) )
install.packages("ggplot2")
if( !is.element("grid", installed.packages()[,1]) )
install.packages("grid")
if( !is.element("plyr", installed.packages()[,1]) )
install.packages("plyr")
if( !is.element("data.table", installed.packages()[,1]) )
install.packages("data.table")
if( !is.element("igraph", installed.packages()[,1]) )
install.packages("igraph")
if( !is.element("ggthemes", installed.packages()[,1]) )
install.packages("ggthemes")
library(ggplot2)
library(grid)
library(plyr)
library(data.table)
library(igraph)
library(ggthemes)
#setwd(dir = "/home/sathya/Documents/coreset/rplots/fig/svm")
svmdata <- fread("ionosphere-smooth-ls-optim.dat")
#svmdata <- read.table("ionosphere-smooth-ls-optim.dat", header=TRUE)
svmdata <- rename(svmdata, c("# k"="k"))
svmdata <- head(svmdata, 100)
svmdata_ls <- fread("ionosphere-ls-optim.dat")
svmdata_ls <- head(svmdata_ls,100)
svmdata_ls <- rename(svmdata_ls, c("# k"="k"))
y_max <- max(max(svmdata$gap), max(svmdata_ls$gap))
base <- ggplot(data=svmdata_ls,aes(x=k, y=gap, group=2)) +
geom_line(colour="#dd3497", size=1.5) + #geom_point(size=4, shape=21) +
geom_line(data=svmdata,aes(x=k, y=gap, group=1 ), colour="#54278f", size=1.5) +
#ggtitle("svmdata_ls gap and svmdata gap vs k") +
geom_smooth(alpha=.2, size=1) +
geom_abline(colour = "grey50", size = 2) +
xlim(0, max(svmdata$k)) +
ylim(0, y_max) +
scale_colour_manual("",
breaks = c("svmdata_ls", "svmdata"),
values = c("#dd3497", "#54278f"))
labelled <- base +
labs(
x = "K",
y = "Gap",
colour = "Cylinders",
title = "svmdata_ls gap and svmdata gap vs k"
)
labelled
styled <- labelled +
theme_bw() +
theme(
plot.title = element_text(face = "bold", size = 25, colour = "purple"),
axis.title=element_text(size= 20, face= "bold", colour="blue"),
legend.background = element_rect(fill = "white", size = 4, colour = "white"),
legend.justification = c(0, 1),
legend.key = element_rect(fill = "yellow"),
#legend.position = "bottom",
legend.position = c(0, 1),
axis.ticks = element_line(colour = "grey70", size = 0.25),
panel.grid.major = element_line(colour = "grey70", size = 0.5),
panel.grid.minor = element_line(colour= "grey70", size=0.5)
)
styled
Data: http://pastebin.com/0wb6S4m8 and http://pastebin.com/L4sdEyYZ
These are just the basics; I didn't bother with all the special colours etc..
to get a legend, combine your data into one long data frame and use aes(colour=grp), where grp is a variable that identifies the group.
to get finer-spaced tick marks, use scale_x_continuous() with breaks or minor_breaks set.
Get data:
rr <- function(x) plyr::rename(as.data.frame(data.table::fread(x)),
c("# k"="k"))
svmdata <- rr("ionosphere-smooth-ls-optim.dat")
svmdata_ls <- rr("ionosphere-ls-optim.dat")
Combine data into a single labeled data frame:
get_vars <- function(d) d[c("k","gap")]
svmcomb <- plyr::ldply(list(svmdata=svmdata,svmdata_ls=svmdata_ls),
get_vars)
Plot:
library(ggplot2)
ggplot(svmcomb,aes(k,gap,colour=.id))+
geom_line()+
scale_x_continuous(minor_breaks=seq(0,100,by=2.5))
Typically with ggplot you would approach this type of thing more like this:
svmdata$grp <- "svmdata"
svmdata_ls$grp <- "svmdata_ls"
dat <- rbind(svmdata,svmdata_ls)
base <- ggplot(data=dat,aes(x=k, y=gap, colour = grp,group=grp)) +
geom_line(size=1.5) + #geom_point(size=4, shape=21) +
geom_line(size=1.5) +
#ggtitle("svmdata_ls gap and svmdata gap vs k") +
geom_smooth(alpha=.2, size=1) +
geom_abline(colour = "grey50", size = 2) +
xlim(0, max(svmdata$k)) +
ylim(0, y_max) +
scale_colour_manual("",
breaks = c("svmdata_ls", "svmdata"),
values = c("#dd3497", "#54278f"))
I collected the data from a set of online forums and wanted to plot, using ggplot and facets (one facet per forum), the matrix that represent how many times user A replied to user B.
Here is the code to load a toy example:
library(ggplot2)
library(dplyr)
df.edges <- data.frame(from = c('forum1_user1', 'forum1_user1',
'forum1_user2', 'forum1_user2',
'forum2_user1', 'forum2_user1',
'forum2_user2', 'forum2_user2',
'forum3_user1', 'forum3_user1',
'forum3_user2', 'forum3_user2'),
to = c('forum1_user1', 'forum1_user2',
'forum1_user1', 'forum1_user2',
'forum2_user1', 'forum2_user2',
'forum2_user1', 'forum2_user2',
'forum3_user1', 'forum3_user2',
'forum3_user1', 'forum3_user2'),
weight = 1:12,
timestamp = 1:12,
subforum = c('forum1', 'forum1', 'forum1', 'forum1',
'forum2', 'forum2', 'forum2', 'forum2',
'forum3', 'forum3', 'forum3', 'forum3'))
I try this:
# Sort for later use in scale_discrete
df.edges <- df.edges %>% arrange(timestamp)
gg <- ggplot(df.edges, aes(x = from, y = to, fill = weight)) +
geom_raster() + coord_fixed() +
facet_grid(. ~subforum, scales='fixed') +
scale_x_discrete("from", aes(limits = from))+
scale_y_discrete("to", aes(limits = from)) +
theme_bw() +
theme(axis.line = element_blank(),
axis.text.x = element_text(angle = 90, hjust=1, size=8),
axis.text.y = element_text(hjust=1, size=10),
axis.ticks = element_blank(),
strip.background = element_rect(fill = 'white'),
aspect.ratio = 1) +
ggtitle("Matrix of interactions") + xlab('from') + ylab('to')
print(gg)
which gives this:
And if I set the facet scale scale='free':
However, I want each facet to show only those users belonging to that forum. The matrices should be completely filled with 4 cells in each one.
Any idea?
You could create a separate plot for each level of subforum and then lay them out together using grid.arrange:
library(gridExtra)
library(grid)
First, create the separate plots and store in a list. We add scale_fill_continuous(limits=range(df.edges$weight)) to ensure a consistent fill gradient across the three plots:
pl = lapply(split(df.edges, df.edges$subforum), function(df) {
ggplot(df, aes(x = from, y = to, fill = weight)) +
geom_raster() + coord_fixed() +
facet_grid(. ~subforum, scales='fixed') +
scale_x_discrete("from", aes(limits = from))+
scale_y_discrete("to", aes(limits = from)) +
scale_fill_continuous(limits=range(df.edges$weight)) +
theme_bw() +
theme(axis.line = element_blank(),
axis.text.x = element_text(angle = 90, hjust=1, size=8),
axis.text.y = element_text(hjust=1, size=10),
axis.ticks = element_blank(),
strip.background = element_rect(fill = 'white'),
aspect.ratio = 1) +
xlab('from') + ylab('to')
})
Extract the legend, as we want only one legend, rather than a separate legend for each plot:
# Function to extract legend
#https://github.com/hadley/ggplot2/wiki/Share-a-legend-between-two-ggplot2-graphs
g_legend<-function(a.gplot){
tmp <- ggplot_gtable(ggplot_build(a.gplot))
leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend <- tmp$grobs[[leg]]
return(legend) }
# Extract legend as a grob
leg = g_legend(pl[[1]])
Arrange the plots with legend and title:
grid.arrange(
textGrob("Matrix of Interactions"),
arrangeGrob(
arrangeGrob(grobs=lapply(pl, function(x) x + guides(fill=FALSE)), ncol=3),
leg, ncol=2, widths=c(10,1)
),
heights=c(1,20)
)
I need a flexible way to make radar / spider charts in ggplot2. From solutions I've found on github and the ggplot2 group, I've come this far:
library(ggplot2)
# Define a new coordinate system
coord_radar <- function(...) {
structure(coord_polar(...), class = c("radar", "polar", "coord"))
}
is.linear.radar <- function(coord) TRUE
# rescale all variables to lie between 0 and 1
scaled <- as.data.frame(lapply(mtcars, ggplot2:::rescale01))
scaled$model <- rownames(mtcars) # add model names as a variable
as.data.frame(melt(scaled,id.vars="model")) -> mtcarsm
ggplot(mtcarsm, aes(x = variable, y = value)) +
geom_path(aes(group = model)) +
coord_radar() + facet_wrap(~ model,ncol=4) +
theme(strip.text.x = element_text(size = rel(0.8)),
axis.text.x = element_text(size = rel(0.8)))
which works, except for the fact that lines are not closed.
I thougth that I would be able to do this:
mtcarsm <- rbind(mtcarsm,subset(mtcarsm,variable == names(scaled)[1]))
ggplot(mtcarsm, aes(x = variable, y = value)) +
geom_path(aes(group = model)) +
coord_radar() + facet_wrap(~ model,ncol=4) +
theme(strip.text.x = element_text(size = rel(0.8)),
axis.text.x = element_text(size = rel(0.8)))
in order to join the lines, but this does not work. Neither does this:
closes <- subset(mtcarsm,variable == names(scaled)[c(1,11)])
ggplot(mtcarsm, aes(x = variable, y = value)) +
geom_path(aes(group = model)) +
coord_radar() + facet_wrap(~ model,ncol=4) +
theme(strip.text.x = element_text(size = rel(0.8)),
axis.text.x = element_text(size = rel(0.8))) + geom_path(data=closes)
which does not solve the problem, and also produces lots of
"geom_path: Each group consist of only one observation. Do you need to
adjust the group aesthetic?"
messages. Som, how do I go about closing the lines?
/Fredrik
Using the new ggproto mechanism available in ggplot2 2.0.0, coord_radar can be defined as:
coord_radar <- function (theta = "x", start = 0, direction = 1)
{
theta <- match.arg(theta, c("x", "y"))
r <- if (theta == "x")
"y"
else "x"
ggproto("CoordRadar", CoordPolar, theta = theta, r = r, start = start,
direction = sign(direction),
is_linear = function(coord) TRUE)
}
Not sure if the syntax is perfect but it is working...
The codes here seem outdated for ggplot2: 2.0.0
Try my package zmisc: devtools:install_github("jerryzhujian9/ezmisc")
After you install it, you will be able to run:
df = mtcars
df$model = rownames(mtcars)
ez.radarmap(df, "model", stats="mean", lwd=1, angle=0, fontsize=0.6, facet=T, facetfontsize=1, color=id, linetype=NULL)
ez.radarmap(df, "model", stats="none", lwd=1, angle=0, fontsize=1.5, facet=F, facetfontsize=1, color=id, linetype=NULL)
if you are curious about what's inside, see my codes at github:
The main codes were adapted from http://www.cmap.polytechnique.fr/~lepennec/R/Radar/RadarAndParallelPlots.html
solution key factor
add duplicated mpg row after melt by rbind
inherit CoordPolar on ggproto
set is_linear = function() TRUE on ggproto
especially is_linear = function() TRUE is important,
since if not you will get plot like this...
with is_linear = function() TRUE settings you can get,
library(dplyr)
library(data.table)
library(ggplot2)
rm(list=ls())
scale_zero_to_one <-
function(x) {
r <- range(x, na.rm = TRUE)
min <- r[1]
max <- r[2]
(x - min) / (max - min)
}
scaled.data <-
mtcars %>%
lapply(scale_zero_to_one) %>%
as.data.frame %>%
mutate(car.name=rownames(mtcars))
plot.data <-
scaled.data %>%
melt(id.vars='car.name') %>%
rbind(subset(., variable == names(scaled.data)[1]))
# create new coord : inherit coord_polar
coord_radar <-
function(theta='x', start=0, direction=1){
# input parameter sanity check
match.arg(theta, c('x','y'))
ggproto(
NULL, CoordPolar,
theta=theta, r=ifelse(theta=='x','y','x'),
start=start, direction=sign(direction),
is_linear=function() TRUE)
}
plot.data %>%
ggplot(aes(x=variable, y=value, group=car.name, colour=car.name)) +
geom_path() +
geom_point(size=rel(0.9)) +
coord_radar() +
facet_wrap(~ car.name, nrow=4) +
theme_bw() +
theme(
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.x = element_blank(),
legend.position = 'none') +
labs(title = "Cars' Status")
final result
Sorry, I was beeing stupid. This seems to work:
library(ggplot2)
# Define a new coordinate system
coord_radar <- function(...) {
structure(coord_polar(...), class = c("radar", "polar", "coord"))
}
is.linear.radar <- function(coord) TRUE
# rescale all variables to lie between 0 and 1
scaled <- as.data.frame(lapply(mtcars, ggplot2:::rescale01))
scaled$model <- rownames(mtcars) # add model names as a variable
as.data.frame(melt(scaled,id.vars="model")) -> mtcarsm
mtcarsm <- rbind(mtcarsm,subset(mtcarsm,variable == names(scaled)[1]))
ggplot(mtcarsm, aes(x = variable, y = value)) +
geom_path(aes(group = model)) +
coord_radar() + facet_wrap(~ model,ncol=4) +
theme(strip.text.x = element_text(size = rel(0.8)),
axis.text.x = element_text(size = rel(0.8)))
It turns out than geom_polygom still produces a polygon in the polar coordinates so that
# rescale all variables to lie between 0 and 1
scaled <- as.data.frame(lapply(mtcars, ggplot2:::rescale01))
scaled$model <- rownames(mtcars) # add model names as a variable
# melt the dataframe
mtcarsm <- reshape2::melt(scaled)
# plot it as using the polygon geometry in the polar coordinates
ggplot(mtcarsm, aes(x = variable, y = value)) +
geom_polygon(aes(group = model), color = "black", fill = NA, size = 1) +
coord_polar() + facet_wrap( ~ model) +
theme(strip.text.x = element_text(size = rel(0.8)),
axis.text.x = element_text(size = rel(0.8)),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
xlab("") + ylab("")
works perfectly...
Thank you guys for the help but it did not cover all of my needs. I used two series of data to be compared so I took the subset of mtcars for Mazda:
nobody mentioned about order of the x variable and ggplot2 sorts this variable for the plot but does not sort the data and it made my chart wrong at the first attempt. Apply sorting function for me it was dplyr::arrange(plot.data, x.variable.name)
I needed to annotate the chart with values and ggplot2::annotate() works fine but it was not included in the recent answers
the above code did not work fine for my data until adding ggplot2::geom_line
Finally this code chunk did my chart:
scaled <- as.data.frame(lapply(mtcars, ggplot2:::rescale01))
scaled$model <- rownames(mtcars)
mtcarsm <- scaled %>%
filter(grepl('Mazda', model)) %>%
gather(variable, value, mpg:carb) %>%
arrange(variable)
ggplot(mtcarsm, aes(x = variable, y = value)) +
geom_polygon(aes(group = model, color = model), fill = NA, size = 1) +
geom_line(aes(group = model, color = model), size = 1) +
annotate("text", x = mtcarsm$variable, y = (mtcarsm$value + 0.05), label = round(mtcarsm$value, 2), size = 3) +
theme(strip.text.x = element_text(size = rel(0.8)),
axis.text.x = element_text(size = rel(1.2)),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
xlab("") + ylab("") +
guides(color = guide_legend()) +
coord_radar()
Hopefully usefull for somebody