Change the last line to
q + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
By default, the axes are aligned at the center of the text, even when rotated. When you rotate +/- 90 degrees, you usually want it to be aligned at the edge instead:
The image above is from this blog post.
You can use a simple list of names :
DF <- data.frame(
x=1:10,
y=10:1,
z=rep(5,10),
a=11:20
)
drops <- c("x","z")
DF[ , !(names(DF) %in% drops)]
Or, alternatively, you can make a list of those to keep and refer to them by name :
keeps <- c("y", "a")
DF[keeps]
EDIT :
For those still not acquainted with the drop
argument of the indexing function, if you want to keep one column as a data frame, you do:
keeps <- "y"
DF[ , keeps, drop = FALSE]
drop=TRUE
(or not mentioning it) will drop unnecessary dimensions, and hence return a vector with the values of column y
.
Best Answer
update: June-22-2018
Thank you @Lorenz@kirill@yuhi for
styler
package. I have used it for a while. The simplest after installation of the package is to just usescroll to
Addin --> style active file
Customization options via interface would give some control on styling we prefer.
Rstudio can now format code to look neat. Select the lines of interest and then navigate to
Code
>>Reformat code
or use the keyboard shortcut Ctrl + Shift + A.update: This is a good way to re-structure the code, but it breaks at
,
for the elements of a vector. For few this is OK, but with many elements passed to a vector, it is overkill:Update: R-Studio Version 0.99.893
There is a new feature that has been added by R-studio
Addins
. Part of this addins, now you can add @yuhi formatR as an Addin. This is more tidy and cleaner way to structure code than the built-incode >> Refromat code
. However, the drawback with the AddinReformat R Code
it throws an error for Rshiny codes.