Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
graphics [2018/03/01 10:20]
qcbs
graphics [2018/10/29 13:35] (current)
qcbs [Exercise 7 - GIFs!]
Line 3: Line 3:
 Offered by Guillaume Larocque, Quebec Centre for Biodiversity Science. ​ Offered by Guillaume Larocque, Quebec Centre for Biodiversity Science. ​
  
-October ​312017. McGill University. ​+October ​302018. McGill University. ​
  
 [[https://​prezi.com/​view/​P9qA6oN11cCAwjay2Hml/​|Link to Prezi presentation.]] [[https://​prezi.com/​view/​P9qA6oN11cCAwjay2Hml/​|Link to Prezi presentation.]]
Line 58: Line 58:
   - Your image should now be blurry on the top and bottom and should have the tilt-shift look. What happens if you now make the mask from step 1 visible? What if you change their order? ​   - Your image should now be blurry on the top and bottom and should have the tilt-shift look. What happens if you now make the mask from step 1 visible? What if you change their order? ​
  
-==== Exercise 4 - GIFs! ==== 
  
-You will be making a GIF animation that highlights how cool your research is!  
- 
-  * Find some photos or graphs from your research that you want to highlight. ​ 
-  * Click on File>New and select a 640x480 document with a White background. ​ 
-  * Open the content you want to put in the animation in GIMP and copy it as new layers using Edit>​Paste as...>​New layer. Resize the content to fit into the page using the Scale Tool.  
-  * Reorder the layers, knowing that the bottom layer will be played first and the top layer last.  
-  * Change the name of each layer to designate the associated content. After the name of the layer add (500ms) to get something like: "First photo(500ms)"​. The number in parenthesis is the duration of this slide in the GIF animation. ​ 
-  * For slides with text, click on the Text tool and and choose the font and font size from the Tool options before adding the text. When you are done placing and resizing the text, add (500ms) to the name of the text layer. ​ 
-  * To give a background to your text, first choose a foreground color by clicking on the Foreground and Background Color icon. Then, add an empty layer to the bottom of the text (by clicking the Create a new layer icon {{::​add_layer_icon.png?​nolink|}}) that has that foreground color. When satisfied with both the text and the background, right click on the text layer and choose Merge Down. The text is now fused with the background and you can't remove it.  
-  * You can test your animation by clicking on Filters>​Animate>​Playback. ​ 
-  * When you are happy with your work, choose File>​Export as>GIF Image, and then click on As animation, leaving the other options unmodified. If it asks if you want to crop, click yes.  
-  * You can now open your animation in a web browser! ​ 
 ===== Inkscape ===== ===== Inkscape =====
 To install Inkscape, go to [[https://​inkscape.org/​en/​release/​0.92.2/​|this site]] and download the version for your platform. If you are on Mac OSX, carefully read the extra steps needed. ​ To install Inkscape, go to [[https://​inkscape.org/​en/​release/​0.92.2/​|this site]] and download the version for your platform. If you are on Mac OSX, carefully read the extra steps needed. ​
-==== Exercise ​====+==== Exercise ​====
  
  
Line 98: Line 85:
   - Export your logo as a PNG image by clicking on File>​Export PNG image. Click on Export area "​Page"​ and then select a size of 500x500px. ​   - Export your logo as a PNG image by clicking on File>​Export PNG image. Click on Export area "​Page"​ and then select a size of 500x500px. ​
  
-==== Exercise 6 ==== +==== Exercize 5 - Using the svglite package.==== 
-You are asked to propose a "​badge"​ for the QCBS that is inspired by the elements of the current logo. You have to use one of the three organisms present on the QCBS logo and a circular photo cutoutwith the QCBS name in a circle around the photo. The final product could look something like this (or not).  +If you are unable ​to do this exercizeyou can download ​the {{ ::fig1.svg |SVG File here}}
-{{::qcbs_relogo_ex.png?​direct&​250|}}+
  
 +  - Install the svglite package and the spocc package<​file rsplus>​install.packages('​svglite'​)
 +install.packages('​spocc'​)</​file>​
 +  - Load the library. <file rsplus>​library(svglite)</​file>​
 +  - Execute the following code to create a pie chart, or adapt the code for another species or to use your own data. <file rsplus>
 +df <- occ(query = 'Puma concolor',​ from = '​gbif',​limit=10000)
 +country_count=as.data.frame(table(df$gbif$data$Puma_concolor$country),​stringsAsFactors=FALSE)
 +country_count<​-country_count[order(country_count$Freq),​]
 +country_count<​-rbind(country_count[country_count$Freq>​50,​],​data.frame(Var1='​Other countries',​Freq=sum(country_count[country_count$Freq<​=50,'​Freq'​])))
  
-  - Create a new Inkscape document and make it 200mmx200mm.  +svglite("​fig1.svg"​) 
-  - Go to [[http://​unsplash.com|Unsplash]] and download a photo that you think would be appropriate for the background of the badge. You can search by keyword ​(e.g. "​texture"​), click on the image you like and then click on download+pie(country_count$Freq,​labels=country_count$Var1) 
-  - Resize the image to 800px wide in GIMP.  +dev.off() 
-  - Copy the image from GIMP to Inkscape using copy-paste. Put it on the side of your page.  +</​file>​ 
-  - Create a circle that fills about 75% of the pageMake the width and height of the circle identical ​in the top menu. Center align the circle on the page, both horizontally and vertically. Make two copies of this circle and keep them on the side. We'll need them later.  +  - You should now have a this file as an SVG on your computerIf you are unsure where it is, type getwd() to identify your working folder.  
-  - Resize your photo and put it under the circle so that the part of the photo that you want to keep is inside ​the circleIf the photo is on top of the circleselect the photo and move it below (PAGE DOWN) +  - You can now open this graphic and modify it in Inkscape  
-  - Select both the circle and the image (press SHIFT while clicking on both)and click on Object>​Clip>​SetNow the photo should be in the form of circle.  +  - If you are curious, your can open this SVG file in Notepad or TextEdit ​to check the structure ​of the SVG/XML fileYou could modify ​the file in text form if you wanted.  
-  - Download this {{::​logo1_trans_no_text.png?​linkonly|png ​file}} containing the QCBS logo in bitmap/​raster ​format. Open it in Inkscape. ​ +  - Note that the text created with svglite has a fixed width (textLength ​is specified in the xml text tagSo, if you increase ​the size of the font, it will become higher but not widerTo fix this problem, open the XML Editor ​(Edit>XML Editor) and clear the textLength section for text objectsYou could also make this change by editing ​the SVG in a text editor.  
-  - We will now turn this image into vector format. ​Click on the QCBS logo and select Path>Trace bitmapSelect single scan and Brightness cutoff. Then click on OK+  - Note that you could also save your file in pdf format ​and open it in Inkscape ​as a PDFIt will still be a vector ​file, but it may be easier to use in some cases than the SVG format. ​<file rsplus> 
-  - There is now a vector version of the logo on top the original one. Click on it and move it to the side.  +pdf("​fig1.pdf"​) 
-  - Click on the new vector logo, and select Path>Break apart. This will separate the elements that don't touch each other.  +pie(country_count$Freq,​labels=country_count$Var1) 
-  - Choose ​which of the owl, the butterfly or the iris you want to isolateIf necessaryremove ​the design elements that protrude out of the organism by double clicking on it and deleting ​the associated nodes (DEL key after clicking on them). You might need to adjust ​the curvature handles.  +dev.off() 
-  - Note that the white elements that were inside ​the black parts have been made blackTo make them "​holes"​ in the objectselect the entire region around the organism ​and click on Path>​CombineThis will make the entire selection whiteMake it black so that you can see it. Select ​the grouped organism ​and copy-paste it to the Inkscape page containing ​the badge.  +</​file>​ 
-  - Resize and move the organism to the approximate center ​of the badge (based on visual perception rather than absolute center). Make it whiteor another color of your choice.  +==== Exercise 6 - Infographic! ==== 
-  - Click on the circle you copied earlier and make the stroke width around 10px and make the stroke dark grey, or what you like. Make the Fill empty (none). Move it on top of the other circle.  +  - Open the graphic created in step 7 in Inkscape
-  - Click on the Create text objects icon (letter A) and click somewhere beside ​the page. Choose a font size of 25 in the top menu barType in the name of the QCBS in full in French ​and English.  +  - Resize ​the document in File>Document properties to 240x160mm.  
-  - Select both the the text and the circle that you (should) have left on the side. Click on Text>Put on path. The text should now be wrapped in a circle. Adjust ​the font size of the text and place it around the badge. Resize as necessary. Note that if you want the bottom portion ​to be upside-upyou need to create two arcsone for the top (French) ​and one for the bottom (English), ​and put the text in each language on around the circle individually +  - Choose ​a color gradient. To facilitate this taskyou can select from the color palette at the bottom of the screenNextclick on the sectors ​of the diagram to change the colors ​and make a gradient from dark for the larger sectors ​to lighter colors for the smaller sectors.  
-  - Click on the organism, go to Filters>Shadow and glow>Drop ShadowChange Horizontal and vertical offsets to 3px and the Blur Color>​Alpha channel of the shadow ​to 200 (mostly opaque).  +  - Choose a contrasting dark color for the background of the infographicNext, create a rectangle that is slightly larger than the page, and specify a background color (Fill) for itYou can use a slight color gradient for the backgroundTo do so, in the Fill and Stroke section, you click on the Gradients option, click on the square hook at the bottom ​of the rectangle, specify a color for thatthen click on the circular hook and choose ​another color for that.  
-  - If you want to add little "​glossy"​ effectyou can create white semi-transparent semi-circular shapes ​on the top and the bottom of the circle (see example badge above)Firststart by creating a square, convert to a path, make it into the shape you wantadjust the position, size and transparency, and move above the photo, but below the other shapes. Repeat for the bottom portion.  +  - You can change ​the size, the color and the position of the labels for the sections ​(country names).  
-  - Adjust other elements to your likingYou have badge! ​+  - Click on the Create ​and edit text objects iconand put a title for the infographic.  
 +  - To add a small paragraph of text, click/drag to delineate where the section of text will beThis way, lines of text will wrap within that section.  
 +  - Choose a photo that you want to put at the centre ​of the diagram on EOL (http://eol.org) by searching with the name of the species. Save this photo to your computer ​and import in Inkscape with File>​Import.  
 +  - Resize approximately ​the image and click on the Create circles, ellipses and arcs icon. Click-drag on the photo to delineate the part of the photo that you want to put in the circle. You can put the circle semi-transparent (Fillchange Opacity) ​to make this easier. Thenselect ​the photo and the circle by clicking ​and holding ​the SHIFT key. Click on Object>Clip>SetThis should crop the photo to a circle. You can release ​the clip at any time to undo this operation and get the complete photo back.  
 +  - Download ​silhouette of your animalor this {{ ::​cougar_silhouette.png?​linkonly |Cougar silhouette}} and open it in Inkscape as a separate file. Click on the silhouette ​and Path>​Vectorize bitmapChoose Colorsspecify 2 passes, and click on OK. You can then select the silhouette in vector format ​by clicking on it and copy-paste it on your infographic. Now, position ​it and choose a color.  
 +  - You can experiment by adding drop shadows to certain elements. To do soselect ​and element and click on Filters>​Shadows and Glows>​Drop shadow
 +  - Export ​your infographic in PNG format 
 +  - Here is an example of {{::​cougar_infographique.png?​linkonly|completed infographic}}. ​
  
  
 +
 +==== Exercise 7 - GIFs! ====
 +
 +You will be making a GIF animation that highlights how cool your research is! 
 +
 +  * Find some photos or graphs from your research that you want to highlight, or use the infographic you created above. ​
 +  * In GIMP, click on File>New and select a 640x480 document with a White background. ​
 +  * Open the content you want to put in the animation in GIMP and copy it as new layers using Edit>​Paste as...>​New layer. Resize the content to fit into the page using the Scale Tool. 
 +  * Reorder the layers, knowing that the bottom layer will be played first and the top layer last. 
 +  * Change the name of each layer to designate the associated content. After the name of the layer add (500ms) to get something like: "First photo(500ms)"​. The number in parenthesis is the duration of this slide in the GIF animation. ​
 +  * For slides with text, click on the Text tool and choose the font and font size from the Tool options before adding the text. When you are done placing and resizing the text, add (500ms) to the name of the text layer. ​
 +  * To give a background to your text, first choose a foreground color by clicking on the Foreground and Background Color icon. Then, add an empty layer to the bottom of the text (by clicking the Create a new layer icon {{::​add_layer_icon.png?​nolink|}}) that has that foreground color. When satisfied with both the text and the background, right click on the text layer and choose Merge Down. The text is now fused with the background and you can't remove it. 
 +  * You can test your animation by clicking on Filters>​Animate>​Playback. ​
 +  * When you are happy with your work, choose File>​Export as>GIF Image, and then click on As animation, leaving the other options unmodified. If it asks if you want to crop, click yes. 
 +  * You can now open your animation in a web browser! ​
  
  
-==== Exercise 7 - Editing R figures in Inkscape with svglite package.==== 
-  
-  - Install the svglite package. <file rsplus>​install.packages('​svglite'​)</​file>​ 
-  - Load the library. <file rsplus>​library(svglite)</​file>​ 
-  - Run the following code to produce a graphic, or adapt this code with one of your own figures from R. <file rsplus> 
-svglite("​fig1.svg"​) 
-tot <- colMeans(VADeaths) 
-text(mp, tot + 3, format(tot),​ xpd = TRUE, col = "​blue"​) 
-barplot(VADeaths,​ beside = TRUE, 
-        col = c("​lightblue",​ "​mistyrose",​ "​lightcyan",​ 
-                "​lavender",​ "​cornsilk"​),​ 
-        legend = rownames(VADeaths),​ ylim = c(0, 100)) 
-title(main = "Death Rates in Virginia",​ font.main = 4) 
-dev.off() 
-</​file>​ 
-  - You should now have the figure in a SVG file in your current working directory. If you are not sure where that is, type getwd(); 
-  - For curiosity, you can open the SVG file in Notepad or TextEdit to see what the structure of the file is like. You could edit the file from there if you wanted! 
-  - Open this image in Inkscape by clicking File>​Open and then selecting the SVG file.  
-  - Change the colors of the bars to make them gradients that start darker at the bottom and become lighter at the top. To do so, click on the bar that you want to adjust, click on Fill and the Linear Gradient icon. Adjust the color of the gradient ends and the orientation by interacting with the gradient handles. When you are happy of one bar with a given gradien, select that bar click on Edit Copy/​CTRL-C,​ select the other bars of the same color and click on Edit>​Paste Style. All bars should now have the same gradient. Repeat with other bars to change the colors as you desire. ​ 
-  - Make the legend bigger by selecting all the elements of the legend (click-drag),​ pressing CTRL-G to make it a group and then resizing it with the resize handles to make it bigger. ​ 
-  - Note that the text in svglite comes with the textLength property set to a given value. So, if you try to change the font size of the text, it will only make the text '​higher'​ and not wider. To fix this, open Edit>XML Editor, and empty out the textLength property for the text objects. Note that you can also remove it from the SVG file in a text editor. ​ 
  
 ===== The R Magick package ===== ===== The R Magick package =====