ggplot2

ggplot2 color - Displays a different color when specified 'red'

人走茶凉 提交于 2021-02-05 08:04:42
问题 I am trying to understand how ggplot2 handles the aesthetics for color. The two ggplot commands shown below display different colors.The second command displays a lighter color, and in addition prints a legend. I appreciate if anyone can throw some light on this concept. data(iris) #1st command ggplot(iris) + geom_point(aes(Sepal.Length,Sepal.Width), color = "red") #2nd command ggplot(iris) + geom_point(aes(Sepal.Length,Sepal.Width, color = "red")) 回答1: aes() maps between variables in the

ggplot2 color - Displays a different color when specified 'red'

和自甴很熟 提交于 2021-02-05 08:03:29
问题 I am trying to understand how ggplot2 handles the aesthetics for color. The two ggplot commands shown below display different colors.The second command displays a lighter color, and in addition prints a legend. I appreciate if anyone can throw some light on this concept. data(iris) #1st command ggplot(iris) + geom_point(aes(Sepal.Length,Sepal.Width), color = "red") #2nd command ggplot(iris) + geom_point(aes(Sepal.Length,Sepal.Width, color = "red")) 回答1: aes() maps between variables in the

Add P values to comparisons within groups boxplot

[亡魂溺海] 提交于 2021-02-05 07:56:50
问题 I'm trying to create a boxplot which shows only the significant p values, within the groups for each bar in a box plot. For example here it would compare I1 and SI2 for the "fair", "good", "very good" etc I've tried using the following code to achieve the above plot library(ggplot2) library(dplyr) data("diamonds") labeldat <- diamonds %>% group_by(cut, clarity) %>% dplyr::summarise(labels = paste(n(), n_distinct(color), sep = "\n")) Comparisons = list(c("I1","SI2"),c("I1","SI1"),c("I1","VS2")

Adding a geom_point at the maximum of a stacked geom_col plot - coloured by a variable outcome

允我心安 提交于 2021-02-05 07:49:08
问题 I have some data which looks like: # A tibble: 50 x 11 V1 V2 V3 V4 V5 V6 V7 V8 GRP ID OUTCOME <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <dbl> 1 0.667 0.539 0.373 -0.774 0.197 -0.0816 -0.0835 0.189 1 166 1 2 -0.436 -0.592 -0.686 -0.364 -0.0200 -0.0360 0.0285 -0.147 1 61 1 3 -0.631 -0.573 -0.705 -0.287 -0.0507 0.0474 0.0182 -0.0702 1 54 1 4 0.418 0.731 0.500 0.262 -0.0979 0.0353 0.0450 0.0156 1 240 0 5 1.03 0.281 -0.0649 -0.670 0.223 0.138 0.0336 0.162 1 179 1 6 -0.200 0.312 0

R ggplot - How to rotate count above barchart

时光毁灭记忆、已成空白 提交于 2021-02-05 07:47:06
问题 My dataframe df look like this Year Frequency 1 1975 86 2 1976 52 3 1977 53 4 1978 54 5 1979 301 6 1980 161 You can use this to reproduce the data.frame yourself: ydf <- structure(list(Year = c(1975, 1976, 1977, 1978, 1979, 1980), Frequency = c(86, 52, 53, 54, 301, 161)), row.names = c(NA, -6L), class = "data.frame") And I plotted this graph with ggplot(ydf, aes(x = Year, y = Frequency, fill=Frequency)) + geom_bar(stat = "identity") + geom_text(aes(label = Frequency), nudge_y=1, check_overlap

How to add a free text entry as a legend to ggplot?

孤者浪人 提交于 2021-02-05 07:27:07
问题 I'm trying to make a world map with a custom legend on the right side. The legend should be with the prepared text on the left and the generated numbers on the right. I tried but to no avail. I need help My code is as follows: library(dplyr) library(ggplot2) library(ggrepel) library(rworldmap) world_map_without_antarctica <- getMap()[-which(getMap()$ADMIN=='Antarctica'),] #get data from web world_map_without_antarctica_t <- fortify(world_map_without_antarctica) Data <- data.frame( "lon"=c(17

Add title name to list of ggplots from the names of dataframes in list

血红的双手。 提交于 2021-02-05 07:16:15
问题 I am producing a list of boxplots from a list of data frames as so: Bps<-lapply(dflist, function(x){ gg<-ggplot(x, aes(x= x, y= y, fill= x))+ geom_boxplot(position = "dodge")+ ggtitle(names(x)) }) The list of dataframes can be generated by: df1<-data.frame(x=seq(1:50), y=rep("Blank", "Non_blank",25)) df2<-data.frame(x=seq(1:40), y=rep("Blank", "Non_blank",20)) df3<-data.frame(x=seq(1:30), y=rep("Blank", "Non_blank",15)) dflist<-list(df1,df2,df3 I need to paste the names of the original

Plotting a line for each row in a Dataframe with ggplot2 in R

拈花ヽ惹草 提交于 2021-02-05 07:12:07
问题 I got the following dataframe describing the age structure in different german districts: I would like to plot one line per row with ggplot in R. An easy solution via matplot in R is: matplot(t(df61[,-c(1,2)], type="l")) which yields: But how is it working with ggplot. I understood, that I have to transform the dataframe into a flat form: library("reshape2") df61_long <- melt(df61[,-2], id.vars = "NAME") Which gives me: I thought that the solution via ggplot should be something like: ggplot

Plotting a line for each row in a Dataframe with ggplot2 in R

家住魔仙堡 提交于 2021-02-05 07:12:05
问题 I got the following dataframe describing the age structure in different german districts: I would like to plot one line per row with ggplot in R. An easy solution via matplot in R is: matplot(t(df61[,-c(1,2)], type="l")) which yields: But how is it working with ggplot. I understood, that I have to transform the dataframe into a flat form: library("reshape2") df61_long <- melt(df61[,-2], id.vars = "NAME") Which gives me: I thought that the solution via ggplot should be something like: ggplot

Best way to plot smooth normal distribution in ggplot

我的未来我决定 提交于 2021-02-05 06:55:46
问题 I would like to plot a nice, 'approaching the limit'-looking normal pdf in ggplot. I found that to get a very symmetric and clean looking plot, I had to crank up the number of samples to a rather large number; one million creates a great visualization. However, this is pretty slow, especially if I hope to work with Shiny at some point. df <- data.frame(c(rnorm(1000000))) ggplot(df, aes(df[1])) + geom_density() Surely there is a better way to display something close to the ideal normal