Questions tagged [ggplot2]

11552 questions
0

votes
0

answer
3

Views

ggplot Box plots side by side

I would like side by side box plots (total and ELISA) by media type. I saw in other chats that I need to melt the data. When I do this I get the following Error: stat_boxplot requires the following missing aesthetics: y media total ELISA surface 1.3 2.7 surface 5.2 6.5 sur...
Ellen
1

votes
1

answer
18

Views

R with ggplot2: Keeping certain rows of a dataframe when making scatter plot

Third week into my R class (please be patient with me even if it seems obvious where went wrong!), and I am struggling with a homework problem on using the R ggplot2 library. Using the built in diamonds dataframe, the problem is to make a scatterplot regression line for log(carat) and log(price), bu...
A.Far
2

votes
1

answer
16

Views

Generating interactive partial dependence plots in R using loop extremely slow

I'm trying to generate interactive partial dependence plots by looping over the columns in the data set. A reproducible example: library(pdp) library(xgboost) library(Matrix) library(ggplot2) library(plotly) data(mtcars) target
Debbie
0

votes
1

answer
5

Views

Graph a cubic in x-intercept form in R

I know that you can create graphs using polynomials, and creating data frames out of them, such as: dat
John
0

votes
2

answer
22

Views

How to change variable value labels WITHOUT changing the variable name

I've got a bar graph whose variable labels (a couple of them) need changing. In the specific example here, I've got a variable 'Sputum.Throat' which refers to samples which could be either sputum or throat swabs, so the label for this value should really read 'Sputum/Throat' or even 'Sputum or Thro...
DanM
0

votes
0

answer
2

Views

How to find out which colours are in a colour palette

I am using ggplot2 to plot a simple graph with scale_color_brewer(palette='Dark2'). I generally like the colour palette, but I would like to change one line of my plot. I think I need to use scale_color_manual. I can change the colours this way, but how to find out which colours are used in the 'Dar...
Talik3233
2

votes
0

answer
13

Views

Follow up of : How to make a sunburst plot in R?

I'm new to R and I would have asked the question directly in the comments but I don't have the reputation yet :D Basically, I wanted to do a sunburst diagram like dmp suggested in this thread: How to make a sunburst plot in R or Python? However, my dataframe looks more like this: df
nathkpa
0

votes
1

answer
18

Views

Removing intermediate years between 1990 and 2010 from the x axis

I am a beginner to R so I apologise in advance if this is a very basic question. I am plotting a box plot showing the type of bars and their various quantities in 1990 and 2010. I have two problems here: I wish to remove the years of 1980, 2000, 2020. I tried using scale_x_discrete('1990','2010') b...
catlovingtaco
1

votes
0

answer
9

Views

Create 2d/3d matrix “object” from data columns and plot it further as contour plot

i got actually stuck in this case already on creating the matrix. Lets start with the data first: Length Diameter Defect Start Defect End Defect Location Defect Angle 1 9850 100 975 987 986 0 2 9850 100 1937 1949 709...
Mal_a
0

votes
0

answer
4

Views

Legend of ggplot2 disppears in ggplotly

I have tried to plot something in ggplot2, and attached is the script: a
ShiMingT
0

votes
2

answer
30

Views

Convert character (or object) variable to numeric (or datetime) variable

I have a monthly data on sales volumes: YearMonth Sales Count 2010-04 300 2010-05 342 2010-06 425 and I just want to draw a line graph in r to observe the trend. I use ggplot2 in r: ggplot(data, aes(x = YearMonth, y = `Sales Count`)) + geom_line() However, r gives me an error m...
Tian
1

votes
0

answer
14

Views

ggplot scale with Yeo-Johnson transformation

I'm trying to create a boxplot with the y-axis transformed with a Yeo-Johnson transformation. Below my code to attempt this but it returns an error, which is below the code. I wrote the code using this LINK. For ease I use an example with the Iris dataset. Please let me know your thoughts on how to...
RmyjuloR
1

votes
1

answer
943

Views

Rotating ggplot2 double-sided barplot

I'm trying to make a horizontal two-sided barplot. So far, the closest I've gotten is with ggplot2 per Two sided bar plot ordered by date. How would I rotate this so that the gene names are on the shared y axis with A on the right and B on the left. Dataset: gene group percentchanged 1 FAM149A...
sm002
1

votes
1

answer
2.7k

Views

How to position the plot legend outside the plot in the bottom-right [closed]

I'm using the latest ggplot2 and currently do p + theme(legend.position='right'). The function theme is well documented and combining bottom and right doesn't seem possible. However, maybe there is an alternate way to achieve this?
SkyWalker
1

votes
2

answer
747

Views

add a second geom_tile layer in ggplot

I have a relatively simple heatmap using geom_tile in ggplot2. It's just a small matrix of continuous data as colored boxes (df1) and I'd like to overlay a second, logical geom_tile that outlines the TRUE values (df2). Can such a thing be done? I know that adding two heatmaps together seems like it...
user4100013
1

votes
1

answer
1k

Views

python ggplot legend size

I've been using the underying matplot lib library to make adjustments that ggplot does not allow me to. p = ggplot(aes(x='meh',y='mah'),data=df) t = theme_gray() t._rcParams['font.size'] = 30 t._rcParams['xtick.labelsize'] = 20 t._rcParams['ytick.labelsize'] = 20 p = p + t This works as expected. I...
LearningSlowly
0

votes
1

answer
28

Views

Save multiple R ggplots ecdf par page into a pdf file with mapply

I compare the empirical CDF of a variable with 3 theoretical CDF. I do this for 150 variables and want to print out the result in a single PDF file with 4 charts per page. I do not use a loop but mapply instead. Ideally, I could use par(mfrow=c(2,2)) but I think this works only for R base objects an...
Bertrand G
0

votes
0

answer
21

Views

Calculate Median of a variable based on other Variable in R

I am using a dataset wherein the values are as follows : ad fl 300 1 400 1 450 2 600 4 700 2 350 1 700 3 900 5 1100 5 700 6 430 3 640 4 I want to plota bar chart based on the median values of ad...
user3759616
1

votes
2

answer
287

Views

Sum variables in a dataframe and plot the sum in ggplot

I have dataframe that contains data on the number of TVs and radios owned by survey respondents now and before: DF % ggplot(aes(x=Number,fill=Device)) + geom_bar(aes(x = Device, y = Number), position = 'dodge', stat = 'identity') This gives me the result I want, but seems unnecessarily complicated...
KaC
1

votes
1

answer
364

Views

different color type and line type for multiple groups in survival curve

I am trying to make a survival plot for three types of different cancers for two different populations. I want each cancer type to have one color and the difference between populations to be the line type (dashed vs solid). So cancer A would be red, with PopA having dashed line and PopB having solid...
Tim Feeney
1

votes
1

answer
21

Views

Shading subregion under Weibull curve in R

I want to do sth like in the figure with a Weibull distribution. But somehow I can't get it to work using stat_function. I get argument missing errors. Adding args=list(..) does not work. limitRange
fitzy_blarb
1

votes
1

answer
45

Views

ggplot scale_fill_* force labels at top and bottom of guide

I'm doing a log transform of a scale_fill, and the top of the scale isn't labeled. For a linear scale, this wouldn't be an issue since it's equidistant, but for a log scale, the value of the max MUST be shown. Is there some way to force that behavior given that the value is not known? EDIT: reprex...
jzadra
1

votes
3

answer
43

Views

Alignment of y axis labels in faced_grid and ggplot?

By using ggplot and faced_grid functions I'm trying to make a heatmap. I have a categorical y axis, and I want y axis labels to be left aligned. When I use theme(axis.text.y.left = element_text(hjust = 0)), each panels' labels are aligned independently. Here is the code: #data set.seed(1) gruplar
serdaryurek
1

votes
2

answer
42

Views

How to make histogram bars to have different colors in Plotly in R

I am making a histogram using plotly package in R and below is the chart. Here is my code: plot_ly(test, x = ~count, type = 'histogram', marker = list(color = 'blue')) I am wondering if there is a way to make the chart more intuitive from a color perspective (eg. different colors for each bar) as t...
MMAASS
1

votes
1

answer
27

Views

Mix different font sizes/faces in plot caption

Using the code below to generate a heat map in R. It works well. The first section is the metric that I use to color the map. My question is how would I have the caption read like below. I know that one would put the first line in front of the other in the section that begins with caption = Paste ('...
Calflamesfann
1

votes
2

answer
45

Views

Plotting all observations but colour them based on different group

I have a sample data given below with sample IDs which are unique, and 3 groups. I need to plot all the observations (rows) in 'df' but color them according to the group IDs ('groupid'). Here's what I have so far: # sample data creation samples
snair1591
1

votes
3

answer
44

Views
1

votes
1

answer
32

Views

ggplot2 - legend for combined geom_point and geom_line

I am given a data set and would like to plot one variable as points and the others as lines with different line types (each variable in a distinct colour). a
Strickland
1

votes
1

answer
30

Views

Recreating a plot from Fundamentals of Data Visualization [on hold]

I'd like to recreate this plot:Fundamentals of Data Visualization. See also below with the screenshot. I have searched the GitHub page link but I cannot find it. Can someone create a plot like a book with many distributions along the horizontal axis? The plot from the book:
David
3

votes
1

answer
30

Views

ggplot right align axis text when using expression

I am making a bar chart with long axis labels which i need to wrap and right align. The only complication is i need to add a expression to have superscripts. library(ggplot2) library(scales) df
clairekelley
0

votes
0

answer
5

Views

ggplot loop graphing columns with matching prefix but different suffix

I have a large data frame that contains a High, Low, and High-Low, for every column. I also have a Base column. I want to create a graph for each set of prefixes so that the line graph has A_H, A_L, A_HL, and Base, and then the same for all of the other matching prefixes. date A_H B_H C_H D_H A...
Kskiaskd
1

votes
2

answer
604

Views

How to output geom_raster() to a raster image?

I'm doing quantitative image analysis, and visualizing the results with ggplot2. The output contains one datapoint for each pixel in the original image. geom_raster() nicely visualizes my data in R. But it would be nice to output a raster image corresponding to the results. That way, I could flip...
Chip Hogg
0

votes
0

answer
14

Views

Loop character values in ggtitle

I have a loop of 4 graphs with a character list like 'a,b,c,d', so in the title of each graph I want 'a', 'b' , 'c' or 'd'. However, when I run my code, 'a' appears in all titles. A part of my code is like this: library(ggplot2) acq
Yria
0

votes
0

answer
40

Views

The mpg dataset in R

I am trying to figure out a way to color my point on a geom_point plot based upon the type of transmission, but in the mpg dataset, the trans column has different names for auto and manual trans. How can I rename the values in the trans column to be either Auto for automatic and Manual for manual tr...
Gavyn Henderson
0

votes
0

answer
3

Views

Plotting PCA, autoplot() doesn't separate colors by group variable

I am using ggplot2 package and ggfortify to plot PCA results. The last column of my data matrix is a column of four different factors. Name of the column is 'group'. It is like: group a b a c d The code I used is: autoplot(prcomp(df), data = mydata, colour = 'group',frame=T) However, in the plot ge...
SZ1042
0

votes
0

answer
13

Views
0

votes
1

answer
23

Views

R ggplot horizontal bars

please I'm having really hard time to probably do something quite simply. I read different posts in here but can't find anything similar to what I would need. I have the following dataframe: sector
Angelo
0

votes
0

answer
15

Views

Plotting time intervals as segments

I have the following dataframe: test_df system type start_date end_date event_duration #> 1 A 2 2015-05-12 2016-07-13 428 #> 2 B 2 2015-06-18 2016-07-02 380 #> 3 B 2 2014-09-11 2015-08-14 337 #> 4 C 2 2015-06-09 2016-04-18...
DeltaIV
1

votes
2

answer
54

Views

apa_print() equations in papaja versus ggplot2 (title)

I am using the papaja package in R markdown (which I love). If I do something like this: The test regression equation was: `r testregressionx1$full_result$modelfit$r2` I will get something like this once I knit to pdf (formatted correctly): R 2 = .10, 90% CI [0.00, 0.45], F(1,10) = 1.07, 239, p = .3...
Kalif Vaughn
1

votes
1

answer
67

Views

Why does ggplot not plot when storing to variable?

I thought this was obvious, but recently I was using the package openair and noticed that when I run the following: library(openair) myplot
rjss

View additional questions