Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9324121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:31:07+00:00 2026-06-19T04:31:07+00:00

I have adapted some very nice code (see below – thanks @Ben-Bolker ) to

  • 0

I have adapted some very nice code (see below – thanks @Ben-Bolker) to create a plot (see below) using mapply so that I do not have to use a loop. I would like to add a trend line for each individual to the existing plot using a similar technique. Any suggestions?

enter image description here

Similar to the following plot (code below):

enter image description here

## sample data ##
WW_Wing_SI <- structure(list(Individual = c("WW_08A_08", "WW_08A_08", "WW_08A_08", 
"WW_08A_08", "WW_08A_08", "WW_08A_08", "WW_08A_08", "WW_08A_08", 
"WW_08A_08", "WW_08B_02", "WW_08B_02", "WW_08B_02", "WW_08B_02", 
"WW_08B_02", "WW_08B_02", "WW_08B_02", "WW_08B_02", "WW_08B_02", 
"WW_08G_01", "WW_08G_01", "WW_08G_01", "WW_08G_01", "WW_08G_01", 
"WW_08G_01", "WW_08G_01", "WW_08G_01", "WW_08G_01", "WW_08G_05", 
"WW_08G_05", "WW_08G_05", "WW_08G_05", "WW_08G_05", "WW_08G_05", 
"WW_08G_05", "WW_08G_05", "WW_08G_05"), Feather = c("1", "2", 
"3", "4", "5", "6", "7", "8", "9", "1", "2", "3", "4", "5", "6", 
"7", "8", "9", "1", "2", "3", "4", "5", "6", "7", "8", "9", "1", 
"2", "3", "4", "5", "6", "7", "8", "9"), Delta15N = c(8.26, 8.1, 
8.07, 8.7, 8.98, 9.44, 7.84, 7.26, 6.05, 6.9, 6.73, 6.97, 6.67, 
6.76, 6.59, 6.58, 6.42, 6.3, 11.64, 11.83, 11.66, 11.3, 11.32, 
11.29, 10.91, 10.77, 11.4, 7.7, 7.8, 8.29, 9.65, 10.25, 13.67, 
14.66, 13.48, 13.76)), .Names = c("Individual", "Feather", "Delta15N"
), row.names = c(NA, 36L), class = "data.frame")

## plot delta15N by feather position for each individual ##
xvals <- tapply(WW_Wing_SI$Feather, WW_Wing_SI$Individual,function(x) return(x))
yvals <- tapply(WW_Wing_SI$Delta15N,WW_Wing_SI$Individual, function(x) return(x))
ID <- unique(WW_Wing_SI$Individual)

par(oma = c(2, 2, 0, 0), mar = c(4, 5, 2, 2), pty = "s")
plot(1:max(unlist(xvals)),ylim=(c(floor(min(unlist(yvals))),ceiling(max(unlist(yvals))))),type="n", bty = "n", 
     cex.lab = 1.75, cex.axis = 1.75, main = NULL, axes = F,
     xlab="Feather Position", ylab=expression(paste(delta ^{15},"N")))
axis(1, at = seq(1, 9, by = 1), labels = T, tick = TRUE, cex.axis = 1.25, cex.lab = 1.25, lwd = 1.25, lwd.ticks = 1.25)
axis(2, at = seq(floor(min(unlist(yvals))), ceiling(max(unlist(yvals))), by = 1), labels = T, tick = TRUE, cex.axis = 1.25, cex.lab = 1.25, lwd = 1.25, lwd.ticks = 1.25)
mapply(lines,xvals, yvals, col = c(1:nrow(xvals)), pch = c(1:nrow(xvals)), type = "o", lty = c(1:nrow(xvals)))

legend("bottom", ID, pch = c(1:nrow(xvals)), col = c(1:nrow(xvals)), cex = 1, pt.bg = c(1:nrow(xvals)), horiz=TRUE, bty = "n")


## Code to accomplish using ggplot ##
WW_Wing_SI$Feather <- as.numeric(WW_Wing_SI$Feather)
library(ggplot2)
theme_set(theme_bw())
ggplot(WW_Wing_SI,aes(Feather,Delta15N,fill=Individual,colour=Individual))+
  geom_line()+geom_smooth(method="lm",formula=y~poly(x,2),linetype=2)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T04:31:08+00:00Added an answer on June 19, 2026 at 4:31 am

    Here’s a proposal. First fit linear models to your data (using lm). Then use these fits to plot the lines:

    fits <- mapply(function(x, y) lm(y ~ as.numeric(x)),
                   xvals, yvals, SIMPLIFY = FALSE)
    mapply(abline, fits, col = seq_along(xvals))
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have adapted some code from a great article I found about circle drawing
I have a very bad feeling about using lock in my code but now
I have adapted some code to populate drop-down selection boxes via MySQL queries, and
I have recently come across a very simple Typed DataTable (without using a .XSD)(I've
I have been using the SeparatedListAdapter which is very well known and works perfectly,
Fragments seem to be very nice for separation of UI logic into some modules.
I have adapted a jQuery tabbed interface tutorial to create an interface for viewing
I have a piece of code written using VS 2005 that works fine in
I have a simple java project (adapted from the example here ), which is
We have a data driven ASP.NET website which has been written using the standard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.