What’s the difference between lapply and do.call?

There is a function called Map that may be similar to map in other languages: lapply returns a list of the same length as X, each element of which is the result of applying FUN to the corresponding element of X. do.call constructs and executes a function call from a name or a function and a list of arguments … Read more

ggplot geom_text font size control

Here are a few options for changing text / label sizes The size in the geom_text changes the size of the geom_text labels. For this And why size of 10 in geom_text() is different from that in theme(text=element_text()) ? Yes, they are different. I did a quick manual check and they appear to be in the ratio of ~ (14/5) for geom_text sizes to theme sizes. … Read more

Categories r

Change size of axes title and labels in ggplot2

You can change axis text and label size with arguments axis.text= and axis.title= in function theme(). If you need, for example, change only x axis title size, then use axis.title.x=. There is good examples about setting of different theme() parameters in ggplot2 page.

Categories r

How to drop columns by name in a data frame

You should use either indexing or the subset function. For example : Then you can use the which function and the – operator in column indexation : Or, much simpler, use the select argument of the subset function : you can then use the – operator directly on a vector of column names, and you can even omit the quotes around the names ! Note that you … Read more

Categories r

Transpose a data frame

You’d better not transpose the data.frame while the name column is in it – all numeric values will then be turned into strings! Here’s a solution that keeps numbers as numbers:

Categories r

Error in library(ggplot2) : There is no package called ‘ggplot2’

When having this issue I would suggest : try turning it off and on again update R to last version if possible remove manually all the folders related to the relevant package and retry the installation change your default library location : How do you change library location in R?

Categories r

How to change line width in ggplot?

Whilst @Didzis has the correct answer, I will expand on a few points Aesthetics can be set or mapped within a ggplot call. An aesthetic defined within aes(…) is mapped from the data, and a legend created. An aesthetic may also be set to a single value, by defining it outside aes(). As far as I … Read more

Categories r

Find duplicate values in R

You could use table, i.e. gives you a data frame with a list of ids and the number of times they occurred. tells you which ids occurred more than once. returns the records with more than one occurrence.

Categories r