It is just equally spaced hues around the color wheel, starting from 15:
gg_color_hue <- function(n) { hues = seq(15, 375, length = n + 1) hcl(h = hues, l = 65, c = 100)[1:n] }
For example:
n = 4 cols = gg_color_hue(n) dev.new(width = 4, height = 4) plot(1:n, pch = 16, cex = 2, col = cols)
Related Posts:
- ggplot wrong color assignment
- ggplot2 line chart gives “geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?”
- ggplot2 line chart gives “geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?”
- Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : Polygon edge not found
- Editing legend (text) labels in ggplot
- Increase number of axis ticks
- ggplot2, facet_grid, free scales?
- Error in plot.new() : figure margins too large, Scatter plot
- Reasons for using the set.seed function
- Error: could not find function “%>%”
- R on MacOS Error: vector memory exhausted (limit reached?)
- R programming: How do I get Euler’s number?
- adding x and y axis labels in ggplot2
- Set NA to 0 in R
- R: Using equation with natural logarithm in nls
- Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
- Non-numeric Argument to Binary Operator Error in R
- What are the “standard unambiguous date” formats for string-to-date conversion in R?
- What are the “standard unambiguous date” formats for string-to-date conversion in R?
- R issue “object not found”
- How do I delete rows in a data frame?
- Remove duplicated rows
- Error in plot.window(…) : need finite ‘xlim’ values
- R ggplot2 scale_y_continuous : Combining breaks & limits
- Add color to boxplot – “Continuous value supplied to discrete scale” error
- Extracting value specific rows in R
- case_when in mutate pipe
- Error in file(file, “rt”) : invalid ‘description’ argument in complete.cases program
- Error in plot.window(…) : need finite ‘xlim’ valuescc
- Longer object length is not a multiple of shorter object length?
- Error: Incorrect number of dimensions in R
- plot.new has not been called yet
- dim(X) must have a positive length when applying function in data frame
- Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, …) : NA/NaN/Inf in ‘y’, tried every possible way
- Persistent invalid graphics state error when using ggplot2
- Error: attempt to use zero-length variable name
- Add text to ggplot
- R error: cannot coerce type ‘closure’ to vector of type ‘double’
- Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, …) : NA/NaN/Inf in ‘y’, tried every possible way
- remove legend title in ggplot
- “replace” function examples
- Why I get this error writing data to a file
- Error in lis[[i]] : attempt to select less than one element
- How to compute weighted mean in R?
- Subscript out of bounds – general definition and solution?
- R: Error in eval(predvars, data, env) : numeric ‘envir’ arg not of length one in intrinsic.pars() in multgee package
- Correlation between multiple variables of a data frame
- Remove all of x axis labels in ggplot
- Remove grid, background color, and top and right borders from ggplot2
- invalid type (list) for variable
- How to subset a Data frame column wise using column names?
- Create an empty data.frame
- How to randomize ggplot factor color scheme, keeping same default distances on color wheel?
- How can I plot data with confidence intervals?
- MLE error in R: initial value in ‘vmmin’ is not finite
- Unimplemented type list when trying to write.table
- How to convert a factor to integer\numeric without loss of information?
- Custom legend for multiple layer ggplot
- `fread` with headers with special characters (latin1) and unusual nested quotes
- How do you create vectors with specific intervals in R?
- predict.lm() in a loop. warning: prediction from a rank-deficient fit may be misleading
- Nested ifelse statement
- Plot multiple lines (data series) each with unique color in R
- reshape2 melt warning message
- Plot a legend outside of the plotting area in base graphics?
- How to sum a variable by group
- readOGR() cannot open file
- lme4 error: boundary (singular) fit: see ?isSingular
- grep using a character vector with multiple patterns
- dcast warning: ‘Aggregation function missing: defaulting to length’
- remove all variables except functions
- R error in unique.default(x) unique() applies only to vectors
- object of type ‘builtin’ is not subsettable
- What’s the difference between facet_wrap() and facet_grid() in ggplot2?
- Combine two data frames by rows (rbind) when they have different sets of columns
- How do I install an R package from source?
- How can I convert Json to data frame in R
- Optimization of a function in R ( L-BFGS-B needs finite values of ‘fn’)
- `Error in file(con, “r”) : cannot open the connection` from running BRugsFit()
- Error in match.fun(FUN)
- How to solve prcomp.default(): cannot rescale a constant/zero column to unit variance
- How Do You Compare Two Strings in R?
- Argument “No” is missing, with no default
- Creating a Plot Window of a Particular Size
- How do I combine two data-frames based on two columns?
- Efficiently sum across multiple columns in R
- Indicator function in R
- Error in eval(predvars, data, env) : object ‘Rm’ not found
- R4DS error comparison (1) is possible only for atomic and list types
- How do I clean up R memory without restarting my PC?
- Deleting rows that are duplicated in one column based on the conditions of another column
- Replace all 0 values to NA
- Side-by-side plots with ggplot2
- Column standard deviation R [duplicate]
- Remove columns from dataframe where some of values are NA
- how to add dashed horizontal line with label in ggplot
- Create a matrix of scatterplots (pairs() equivalent) in ggplot2
- increase legend font size ggplot2
- Filter rows which contain a certain string
- In R, dealing with Error: ggplot2 doesn’t know how to deal with data of class numeric