ggplot2

plot polynomial regression line with ggplot stat_smooth

懵懂的女人 提交于 2021-02-20 19:05:21
问题 I'm trying to create a scatter plot with second degree polynomial regression line using ggplot:stat_smooth. Here are the codes: df.car_spec_data <- read.csv(url("http://www.sharpsightlabs.com/ wp- content/uploads/2015/01/auto-snout_car-specifications_COMBINED.txt")) df.car_spec_data$year <- as.character(df.car_spec_data$year) df.car_spec_data %>% group_by(year) %>% summarise(maxspeed=max(top_speed_mph, na.rm=T)) %>% ggplot(aes(x=year, y=maxspeed, group=1))+geom_point(color='red', alpha=0.3,

ggplot2 issue with facets and turning off clipping

流过昼夜 提交于 2021-02-20 06:24:43
问题 It used to be possible to put text on plot margins by turning off clipping. In ggplot2_2.2.0 this doesn't seem to be possible anymore in plots that use facets (but still works if no facets are used). I've posted an issue here but it has not been addressed yet. Any ideas for workarounds in the meantime would be greatly appreciated! Here is a minimal (non-)working example: library(ggplot2) library(grid) df.plot = data.frame(x = 1, y = 1, facet = 'facet', stringsAsFactors = F) df.text = data

mapping (ordered) factors to colors in ggplot

有些话、适合烂在心里 提交于 2021-02-20 04:05:55
问题 Consider this example data_frame(mylabel = c('month 18', 'month 19', 'month 20', 'month 21', 'month 22'), value = c(5,10,-2,2,0), time = c(1,2,3,4,5)) %>% ggplot(aes( x= time, y = value, color = mylabel)) + geom_point(size = 7) Here you can see that the variable mylabel has a natural ordering: month 18 comes before month 19 etc. However, this natural ordering is not preserved by the colors chosen by ggplot . In my real dataset, I have about 50 different months and I would like to use a color

mapping (ordered) factors to colors in ggplot

℡╲_俬逩灬. 提交于 2021-02-20 04:05:49
问题 Consider this example data_frame(mylabel = c('month 18', 'month 19', 'month 20', 'month 21', 'month 22'), value = c(5,10,-2,2,0), time = c(1,2,3,4,5)) %>% ggplot(aes( x= time, y = value, color = mylabel)) + geom_point(size = 7) Here you can see that the variable mylabel has a natural ordering: month 18 comes before month 19 etc. However, this natural ordering is not preserved by the colors chosen by ggplot . In my real dataset, I have about 50 different months and I would like to use a color

mapping (ordered) factors to colors in ggplot

冷暖自知 提交于 2021-02-20 04:04:12
问题 Consider this example data_frame(mylabel = c('month 18', 'month 19', 'month 20', 'month 21', 'month 22'), value = c(5,10,-2,2,0), time = c(1,2,3,4,5)) %>% ggplot(aes( x= time, y = value, color = mylabel)) + geom_point(size = 7) Here you can see that the variable mylabel has a natural ordering: month 18 comes before month 19 etc. However, this natural ordering is not preserved by the colors chosen by ggplot . In my real dataset, I have about 50 different months and I would like to use a color

Regarding factoring in R

99封情书 提交于 2021-02-20 03:51:43
问题 I have this code where currently I am displaying for 2 patients but I have to group the 3 records and display them for more than 15 patients. Currently I am factoring for each patients as below but is there any way to use factor with grep so that my factor won't become so tedious pat_paste_c<-factor(pat_paste_c,levels=c('Pat_1_IT-6','Pat_1_IT-7','Pat_1_IT-8',"Pat_2_IT-6","Pat_2_IT-7","Pat_2_IT-8"),ordered = TRUE) c<- data.frame(Var=character(), Pat_1=double(), Pat_2=double(), stringsAsFactors

Using ggplot2 in R creating multiple smoothed/fitted lines

空扰寡人 提交于 2021-02-20 02:57:28
问题 I am having trouble producing a figure in R using ggplots. No stats are needed - I just need the visual representation of my data. I have 7 participants, and I want to plot a line for each participant through a scatterplot. The slope and shape of the line is different for each participant, however on average is somewhat exponential. I have used the below code in R, however I am only getting liner models. When changing the method to loess, the lines are too wriggly. Can someone please help me

Using ggplot2 in R creating multiple smoothed/fitted lines

荒凉一梦 提交于 2021-02-20 02:56:47
问题 I am having trouble producing a figure in R using ggplots. No stats are needed - I just need the visual representation of my data. I have 7 participants, and I want to plot a line for each participant through a scatterplot. The slope and shape of the line is different for each participant, however on average is somewhat exponential. I have used the below code in R, however I am only getting liner models. When changing the method to loess, the lines are too wriggly. Can someone please help me

How to zoom in on a specific range of values for a categorical variable in ggplot2?

北城以北 提交于 2021-02-20 02:20:55
问题 I just want to zoom in on the x-axis between the values ford and nissan in the mpg dataframe. Package used: tidyverse But I am getting the following error when using the coord_cartesian() function: p<-ggplot(mpg,aes(x=manufacturer,y=class)) p+geom_point()+ + coord_cartesian(xlim = c('ford','nissan')) Error in +coord_cartesian(xlim = c("ford", "nissan")) : invalid argument to unary operator 回答1: You can use a function for contextual zoom from ggforce package ( facet_zoom ) to achieve this: #

How to zoom in on a specific range of values for a categorical variable in ggplot2?

南笙酒味 提交于 2021-02-20 02:16:39
问题 I just want to zoom in on the x-axis between the values ford and nissan in the mpg dataframe. Package used: tidyverse But I am getting the following error when using the coord_cartesian() function: p<-ggplot(mpg,aes(x=manufacturer,y=class)) p+geom_point()+ + coord_cartesian(xlim = c('ford','nissan')) Error in +coord_cartesian(xlim = c("ford", "nissan")) : invalid argument to unary operator 回答1: You can use a function for contextual zoom from ggforce package ( facet_zoom ) to achieve this: #