coffee-digital

Coffee Digital - Mapping and Analysis Project πŸŒ±β˜•

This repository contains R scripts for analyzing and visualizing coffee farm data, including static maps with satellite imagery and interactive web maps. The project focuses on mapping coffee farms across different communities and categories using geographic data.

πŸ“‹ Table of Contents

🎯 Overview

This project analyzes coffee farm data across different communities and categories, creating both static and interactive visualizations. The analysis includes:

Key Features

πŸ“ Project Structure

coffee-digital/
β”œβ”€β”€ README.md                    # Project documentation
β”œβ”€β”€ LICENSE                      # License file
β”œβ”€β”€ .gitignore                  # Git ignore rules
β”œβ”€β”€ config.R.example           # Configuration template
β”œβ”€β”€ config.R                   # API keys (not in version control)
β”‚
β”œβ”€β”€ data/                       # Data directory
β”‚   β”œβ”€β”€ derived/               # Processed data
β”‚   β”‚   β”œβ”€β”€ coffee_sample_final_20250709.rds
β”‚   β”‚   └── coffee_sample_final_20250709.xlsx
β”‚   β”œβ”€β”€ org/                   # Original data files
β”‚   β”‚   β”œβ”€β”€ 3.Fincas_seleccionadas.xlsx
β”‚   β”‚   β”œβ”€β”€ Base_vieja.xlsx
β”‚   β”‚   β”œβ”€β”€ Fincas_actualizado_final2.xlsx
β”‚   β”‚   β”œβ”€β”€ pioners.xlsx
β”‚   β”‚   └── TREATMENT VS CONTROL_2.R
β”‚   └── Shapes/               # Shapefiles for geographic boundaries
β”‚       β”œβ”€β”€ shapes.shp
β”‚       β”œβ”€β”€ shapes.dbf
β”‚       β”œβ”€β”€ shapes.prj
β”‚       β”œβ”€β”€ shapes.cpg
β”‚       └── shapes.shx
β”‚
β”œβ”€β”€ syntaxis/                  # R scripts
β”‚   β”œβ”€β”€ 01_Sampling_Random_Selection.R
β”‚   β”œβ”€β”€ 02_create_maps.R      # Main mapping script
β”‚   β”œβ”€β”€ 03_interactive_maps.R # Interactive map creation
β”‚   β”œβ”€β”€ aux_func_distacia.R   # Distance calculation functions
β”‚   └── old_check_old_ds.R    # Data validation
β”‚
└── out/                      # Output directory (generated)
    β”œβ”€β”€ map_all.png          # General overview map
    β”œβ”€β”€ map_[community].png  # Individual community maps
    └── interactive_map.html # Interactive web map

πŸ› οΈ Setup and Installation

Prerequisites

Required R Packages

The project uses pacman for package management. The following packages are automatically installed:

# Core packages
- ggplot2      # Data visualization
- ggmap        # Google Maps integration
- sf           # Spatial data handling
- leaflet      # Interactive maps
- htmlwidgets  # Web widgets for R

Installation Steps

  1. Clone the repository:
    git clone https://github.com/yourusername/coffee-digital.git
    cd coffee-digital
    
  2. Set up Google Maps API key:

    Option A: Environment Variable (Recommended)

    export GOOGLE_MAPS_API_KEY="your_api_key_here"
    

    Option B: Configuration File

    cp config.R.example config.R
    # Edit config.R and add your API key
    
  3. Create output directory:
    mkdir -p out
    
  4. Run the scripts in RStudio or R console

πŸš€ Usage

Quick Start

  1. Generate all maps:
    source("syntaxis/02_create_maps.R")
    
  2. Create interactive map:
    source("syntaxis/03_interactive_maps.R")
    

Detailed Workflow

  1. Data Preparation: Load and process coffee farm data
  2. Static Maps: Generate satellite maps with farm locations
  3. Community Maps: Create individual maps for each community
  4. Interactive Maps: Build web-based interactive visualizations

πŸ“œ Scripts Description

01_Sampling_Random_Selection.R

02_create_maps.R ⭐ Main Script

03_interactive_maps.R 🌐 Interactive Maps

aux_func_distacia.R

old_check_old_ds.R

🎨 Output Examples

Static Maps

Overview Map (map_all.png)

Community Maps (map_[community].png)

Individual maps for each community with:

Interactive Map (interactive_map.html)

Features:

πŸ“Š Data

Farm Categories

Data Sources

βš™οΈ Configuration

Google Maps API Setup

  1. Get API Key:
  2. Configure in Project:
    # In config.R
    google_maps_api_key <- "YOUR_API_KEY_HERE"
    
  3. Security Note:
    • Never commit API keys to version control
    • Use environment variables in production
    • Restrict API key usage by domain/IP

Customization Options

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Guidelines

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Troubleshooting

Common Issues

  1. Google Maps API Errors:
    • Check API key validity
    • Verify API quotas
    • Ensure Maps JavaScript API is enabled
  2. Missing Packages:
    • Run install.packages("pacman") first
    • Check R version compatibility
  3. File Path Issues:
    • Ensure working directory is project root
    • Check file permissions
    • Verify data file existence

Support

For issues and questions:


Last Updated: July 9, 2025
Project Status: Active Development
R Version: 4.0+