GithubHelp home page GithubHelp logo

ggradar's Introduction

ggradar

ggradar allows you to build radar charts (aka spider charts) with ggplot2. This package is based on Paul Williamson’s code, with new aesthetics and compatibility with ggplot2 2.0.

It was inspired by d3radaR, an htmlwidget built by timelyportfolio.

Install ggradar

devtools::install_github("ricardo-bion/ggradar", 
                          dependencies = TRUE)

Use ggradar

library(ggradar)
library(dplyr)
library(scales)
library(tibble)

mtcars_radar <- mtcars %>% 
  as_tibble(rownames = "group") %>% 
  mutate_at(vars(-group), rescale) %>% 
  tail(4) %>% 
  select(1:10)
group mpg cyl disp hp drat wt qsec vs am
Ford Pantera L 0.2297872 1.0 0.6981791 0.7491166 0.6728111 0.4236768 0.0000000 0 1
Ferrari Dino 0.3957447 0.5 0.1843352 0.4346290 0.3963134 0.3214012 0.1190476 0 1
Maserati Bora 0.1957447 1.0 0.5734597 1.0000000 0.3594470 0.5259524 0.0119048 0 1
Volvo 142E 0.4680851 0.0 0.1244699 0.2014134 0.6221198 0.3239581 0.4880952 1 1
ggradar(mtcars_radar)

Custom fonts

You can also use custom font family in ggradar. In the following example, you would like to use Airbnb’s font family named ‘Circular Air’ by first download it, install it in your computer, and then register it to R using extrafont package.

# configured to work on a Mac, change directory to Unix or Windows
download.file("https://github.com/ricardo-bion/ggtech/blob/master/Circular%20Air-Light%203.46.45%20PM.ttf", "~/Circular Air-Light 3.46.45 PM.ttf", method = "curl")

extrafont::font_import(pattern = 'Circular', prompt = FALSE)

Following the same procedure as in the previous example, you can then use ‘Circular Air’ font family in ggradar by adjusting font.radar argument. The following example shows that ggradar is also can be used in pipe %>%.

mtcars %>% 
  as_tibble(rownames = "group") %>% 
  mutate_at(vars(-group), rescale) %>% 
  tail(4) %>% 
  select(1:10) %>% 
  ggradar(font.radar = "Circular Air")

ggradar's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ggradar's Issues

Local installation not working

I downloaded the zip file and tried to install the package ggradar as follows

library(devtools)
devtools::install("E:\\Programme\\r_pckg\\ggradar-master", type = "source")

This throws the following error
Error: Could not find package root.

How can I install the package from a local directory?

ggradar2 asks for your permission

Hi Ricardo, thanks to your ggradar package, I am able to use radar chart to do data analysis. I found that more features can be added in the function, but it seems like that you have no time to maintain it. For the convenience reason, I have built a new package called 'ggradar2', which is based on your code. But some customizable features have been added and some syntax are adjusted to make code run in a right way. I am planning to add more features. So I am wondering if I may have your authorization to share the new package?

Issues with ggradar

Hi, Ricardo.

I'm starting to use your package ggradar and I'm having a few problems:

  1. I can't reduce the size of the legend labels. I've used legend.text.size=5 with no avail.
  2. I can't set a legend title. I've tried legend.title with no result as well.

Despite of that, it's a great package.

Renato

Error: expecting a one sided formula, a function, or a function name.

I have a data that looks like this with 10 rows

ld kt ts ss ss1 ss2 ss3
1 5 1 165 88 54 57 110
2 5 2 167 91 65 58 110
3 6 1 183 107 50 69 110

if I do following

data%>%filter(kt==1)%>%rename(group=스) %>% mutate_at(vars(-group),scales::rescale())

I get an error

Error: expecting a one sided formula, a function, or a function name.

If I don't do "scales::rescale()" I get an error saying

Error in check_dot_cols(.vars, .cols) : object 'rescale' not found

I've tried

data%>%filter(kt==1)%>%rename(group=스) %>% mutate_each(funs(rescale),-group)

and I get

Error in is_character(x) : object 'group' not found

can you help?

Error: plot.data' contains value(s) < centre.y

dat <- structure(list(tuition_and_fees_as_pct_total_rev_slope = 0.0116275839552173, 
    total_student_grants_as_pct_total_rev_slope = -0.0151290805847034, 
    govt_appropriations_grants_as_pct_total_rev_slope = 0.567182878972684, 
    sales_or_other_earned_revenue_as_pct_total_rev_slope = 0.168715061124856, 
    instruction_exp_as_pct_total_exp_slope = -0.265842023491547, 
    research_exp_as_pct_total_exp_slope = 0.256877374064898, 
    public_service_exp_as_pct_total_exp_slope = -0.260728569639251, 
    academic_support_as_pct_total_exp_slope = 0.0924740814929788, 
    student_service_as_pct_total_exp_slope = -0.038056463747445, 
    institutional_support_as_pct_total_exp_slope = -0.195679948781814, 
    total_debt_to_total_assets_ratio_slope = 0.164338557482071), row.names = c(NA, 
-1L), class = c("tbl_df", "tbl", "data.frame"))

ggradar(dat)
# Error: plot.data' contains value(s) < centre.y

Error saving the plot in pdf

Hi when I run the example and try to save using pdf() or ggsave I have this error:

Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
invalid font type
In addition: There were 46 warnings (use warnings() to see them)
The warnings are:

1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... :
font family 'Circular Air Light' not found in PostScript font database

a param for changing font family?

Hi, thanks for this package. It's pretty cool.

However, I notice that you hard-coded the font family in function ggradar ( family="Circular Air Light" ) without allowing users to assign their preferred font (correct me if I'm wrong), which is inconvenient for users (e.g., I want use a Chinese font).

Is there any specific reason that the family has to be hard-coded?

Thanks.

How to show the actual value in the plot?

Thank you for building such a wonderful tool for us. Recently I have a task to draw a radar chart and should put the actual value near the dots. Is there a way to implement it in ggradar? Or can I change some codes and add it by myself?

Thanks.

ggradar not working

It seams that something is wrong with the current version of R.
Running the example

library(ggradar)
library(dplyr)
library(scales)
library(tibble)

mtcars_radar <- mtcars %>%
as_tibble(rownames = "group") %>%
mutate_at(vars(-group), rescale) %>%
tail(4) %>%
select(1:10)

results in the follow image
Rplot

I had some examples of my own that are not running well now.

base.size not functional

the base.size parameter is not functional. changing the value has no effect on text size in the ggradar chart

Quantiles/the 50% line

I did some work on radars recently and used your package as one starting point to build my own package. That said, I was quite irritated by the 50% lines in your plot. They are not the 50% quantiles. They are just the middle between the maximum and the minimum values in your radar.

Don't know whether this problem belongs here - I'm new - but I would suggest to remove them or at least to remove them from the default option. Some hint in the documentation would also help.

Polygon edge not found

Using the example from the readme:

> download.file("https://dl.dropboxusercontent.com/u/2364714/airbnb_ttf_fonts/Circular Air-Light 3.46.45 PM.ttf", "/Library/Fonts/Circular Air-Light 3.46.45 PM.ttf", method="curl")
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0100  216k  100  216k    0     0   491k      0 --:--:-- --:--:-- --:--:--  491k
> 
> extrafont::font_import(pattern = 'Circular', prompt=FALSE)
Scanning ttf files in /Library/Fonts/, /System/Library/Fonts, ~/Library/Fonts/ ...
Extracting .afm files from .ttf files...
/Library/Fonts/Circular Air-Light 3.46.45 PM.ttf => /Users/amos.elberg/Library/R/3.3/library/extrafontdb/metrics/Circular Air-Light 3.46.45 PM
Found FontName for 1 fonts.
Scanning afm files in /Users/amos.elberg/Library/R/3.3/library/extrafontdb/metrics
Writing font table in /Users/amos.elberg/Library/R/3.3/library/extrafontdb/fontmap/fonttable.csv
Writing Fontmap to /Users/amos.elberg/Library/R/3.3/library/extrafontdb/fontmap/Fontmap...
> library(ggradar)
> 
> suppressPackageStartupMessages(library(dplyr))
> library(scales)
> 
> mtcars %>%
+      add_rownames( var = "group" ) %>%
+      mutate_each(funs(rescale), -group) %>%
+      tail(4) %>% select(1:10) -> mtcars_radar
Warning message:
Deprecated, use tibble::rownames_to_column() instead. 
> 
> ggradar(mtcars_radar) 
Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found

Any suggestions?

Editing label font: italics, etc?

Love the package - it's been a gamechanger for my work. Is there a way to set the label font to italics or bold? Looks like this can't be set in a theme as it appears that the label font is set with geom_text. I see that there is font.radar but that only allows changing the font family, not fontface.

Thank you!
David

little error for plot legend

Hi Ricardo,

Thanks for this great library !

There is a little mistake at the end of the function though: you add + theme(legend.title = element_blank()) regardless of the legend.title attribute.

Easy to workaround (just add + theme(legend.title = element_text()) to your ggradar) but it should also be easy to correct.

Dan

Legend still showing although plot.legend=FALSE

Thanks for this package!
I am trying to produce a radar chart without a legend, but somehow the legend always shows up.

Example and result

library(ggplot2)
library(ggradar)

df <- data.frame(Name="Object_xx",Zustand=0.8, V1=0.5, V2=0.5, V3=0.5, V4=0.363)
r_chart <- ggradar(plot.data=df,
                   font.radar = "Helvetica",
                   grid.label.size = 4,
                   axis.label.size = 4,
                   plot.legend = T
                   )
plot(r_chart)

gives the following result:

rplot

However, what I want is this:

rplot_copy

Add extra grid line, not limited to min,median and max

I'm so excited to use this package to draw beautiful radar plot. And I found some limitation, I want to show the 20th, 40th, 60th and 80th lines or other value in the background, but this package can only set 0,0.5 and 1. So is there any way to fix this problem?

Make CRAN release

Can we get a CRAN release of this? Requiring devtools to get this package is a big dependency.

Error: 'plot.data' contains value(s) > grid.max

Hi Ricardo - could you possibly advise what I'm doing wrong here?

require(ggplot2); require(ggradar); require(dplyr); require(tidyr)
dat = data.frame(month = rep(month.abb, 3) %>% factor(month.abb), group = rep(c('A','B','C'), each=12),
                 val = c(sample(11:22), sample(21:32), sample(31:42))) %>% spread(month, val)
dat
#>   group Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
#> 1     A  11  20  15  21  17  19  13  14  12  18  22  16
#> 2     B  21  31  27  24  22  26  32  29  28  25  30  23
#> 3     C  32  36  40  31  35  42  33  37  39  41  34  38
ggradar(dat)
#> [1] "Error: 'plot.data' contains value(s) > grid.max"

Error bars for groups

Apologies if I missed the function, but I was wondering if it would be possible to plot error bars with ggradar, either (1) using a tibble with the grouping factor and the variables as columns, and one row per observation in each group, or (2) using a tibble with the grouping factor, the variables (means) and the error (standard deviations) as columns, and a single row per group.

The first way seems more straightforward, with maybe an argument in ggradar() to state what kind of error to calculate (using a fun=), but the second way seems closer to the current way ggradar works (one row per group).

fill color function

Is a fill function incorporated into your package? I am trying to fill the polygon with a color and transparency value and have not been able to find the syntax.

Thank you

had non-zero exit status

I tried to install package ggradar but the installation seems to fail, (for windows ) and i´ve rtools

devtools::install_github("ricardo-bion/ggradar", dependencies = TRUE)

Downloading GitHub repo ricardo-bion/ggradar@HEAD
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

1: All
2: CRAN packages only
3: None
4: ellipsis (0.3.1 -> 0.3.2 ) [CRAN]
5: rlang (0.4.10 -> 0.4.11) [CRAN]

Enter one or more numbers, or an empty line to skip updates:
√ checking for file 'C:..\ricardo-bion-ggradar-63e5cef/DESCRIPTION' (489ms)

  • preparing 'ggradar':
    √ checking DESCRIPTION meta-information ...
  • checking for LF line-endings in source and make files and shell scripts
  • checking for empty or unneeded directories
  • building 'ggradar_0.2.tar.gz'

Installing package into ‘C:../R/win-library/4.0’
(as ‘lib’ is unspecified)

  • installing source package 'ggradar' ...
    ** using staged installation
    ** R
    ** byte-compile and prepare package for lazy loading
    Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
    namespace 'ellipsis' 0.3.1 is being loaded, but >= 0.3.2 is required
    Calls: ... asNamespace -> loadNamespace -> namespaceImport -> loadNamespace
    Execution halted
    ERROR: lazy loading failed for package 'ggradar'
  • removing 'C:../OneDrive/Documentos/R/win-library/4.0/ggradar'
    Warning message:
    In i.p(...) :
    installation of package ‘C: .../ggradar_0.2.tar.gz’ had non-zero exit status

Default legend text size too small relative to base text size

Thanks for this package!
I noticed when updating the Readme that when using all default arguments, the legend text size is now extremely small by default compared to the rest of the text. Looks like this is because base text size is 20 while default legend text size is 7. Of course users can update the legend text size but might be good to have better matching defaults.

Example and result below:

library(tibble)
mtcars %>%
     rownames_to_column( var = "group" ) %>%
     mutate_at(vars(-group),funs(rescale)) %>%
     tail(4) %>% select(1:10) -> mtcars_radar

g <- ggradar(mtcars_radar)

unnamed-chunk-2-1

Windows could not find font family

Using the latest version from github, the plot appears to work fine but none of the labels show up.

"font family not found in Windows font database"

PDF export

fantastic work ! Helps me a lot for my projects.. However, is there a way to export in PDF? Any attempt leads to export in PDF leads to a white blank sheet.. Sorry, Im new here

how can i change the linetype for plotted variables in ggradar?

Hi,

I would like to assign different linetypes for plotting two different sets of variables in ggradar. I tried something like
group.linetype = c("longdash", "solid")
or
group.line.type = c("longdash", "solid")
or
group.line.linetype = c("longdash", "solid")

None of the options work for me. What would be the right synthax to change that?

And another issue is that ggradar seems to order the variables automatically in an alphabetical order when plotting and putting together the legend. Can I change that default setting and keep the order of variables according to my dataset?

Many thanks for your great help!

Cheers

Susi

adding font color argument

I love this package! Any chance you can add in a font color argument in the future? I see there's font.size, would be cool to add a font color to allows users to customize value labels and axis labels. Please let me know it exists and I've missed it in the documentation.

Radar graph with missing values

Hi Ricardo,

I've been trying to do a ggradar plot with some missing values, and the following error pops up:

Error in if (min(plot.data[, -1]) < centre.y) { :
missing value where TRUE/FALSE needed

The code which I've run is the following:

library(ggradar)
library(dplyr)
library(scales)
library(tibble)
datos=read.table(file = "Datos_SDM.csv", sep = ";", header = T, dec = ",")
head(datos)
data= datos[, c(2:13)]
head(data)
row.names(data)= c("2010", "2020", "2030", "2040", "2050")
data
data_radar= data%>%
as_tibble(rownames = "year")%>%
mutate_at(vars(-year), rescale, to= c(0, 10))%>%
select(1:6)
ggradar(data_radar, values.radar = c("0", "2", "4", "6", "8", "10"), grid.min = 0, grid.mid = 5, grid.max = 10)

Is it possible to do a ggradar plot with missing values? If so how should I do it?

Many thanks,
Javier

Display actual values instead of coordinates when using ggplotly in combination with ggradar

I use ggradar in combination with plotly to create a radar chart. After using plotly to obtain the hover-text ability I get the coordinates of every point when I mouse over each point but this does not make sense to me. How can I get the actual values instead of coordinates?

library(ggradar)
library(dplyr)
library(scales)
library(tibble)
library(plotly)
mtcars_radar <- mtcars %>% 
  as_tibble(rownames = "group") %>% 
  mutate_at(vars(-group), rescale) %>% 
  tail(4) %>% 
  select(1:10)

p<-ggradar(mtcars_radar)
ggplotly(p)

object 'values.radar' not found

Hi, I am running the example code but got the error:

Error in FUN(X[[i]], ...) : object 'values.radar' not found

How can I resolve this?
Thanks

Example fails on MacOS

Example output:

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found
In addition: There were 50 or more warnings (use warnings() to see the first 50)

Also, the Circular Air Light TTF font does not install correctly on MacOS. That is what the warnings are about.

Error with rescaling

Hi @ricardo-bion, I have a problem with rescaling... can you help me? I'm not so good in R, so maybe there's something I'm missing :)

genus <- read.delim("per_radar-chart.txt")
genus_radar <- genus %>%
  mutate_each(funs(rescale), -Group) %>%
  select(1:5) %>%
  ggradar()

What I get is a fancy radar plot with only values 0 or 100%, not even a middle one... while my data file is:

Group	Bacteroides	Faecalibacterium	Unclassified Ruminococcaceae	Ruminococcus	Escherichia	Unclassified Clostridiales	Akkermansia	Unclassified Lachnospiraceae	Roseburia	Dialister	Coprococcus	Oscillospira	Unclassified Rikenellaceae	Veillonella	Clostridium	Streptococcus	[Ruminococcus]	Blautia	SMB53	Parabacteroides	Phascolarctobacterium	Megamonas	Citrobacter	Lachnospiraceae (other)
HC	18.82899325	19.60617616	8.940147657	7.249336029	0.988030541	6.865308901	1.631560454	4.483545652	3.265902473	3.56638604	2.428487019	3.348809198	2.354368114	0.412104445	0.757058557	0.514498255	1.19583613	1.395051977	0.291326573	1.072784808	0.5056626	0.000374976	0.06799222	0.744098443
GSD	14.42678147	7.435798578	5.266405696	1.422892644	10.01335203	0.289875818	6.264758224	1.410419752	1.49970791	1.644507887	2.800174931	0.635045002	1.871660707	4.72936867	3.937134304	4.155349914	2.520429148	1.826753366	3.049466559	0.839257497	1.584002305	5.643196915	5.331207737	0.516412005

Can you help me? Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.